Angularjs UI的选择(选择2)不与“控制器”语法工作没有得到选择伊特 [英] Angularjs ui-select (select2) not working with 'Controller as' syntax not getting selected ite
问题描述
我想获得一个选择HTML控件与AngularJS UI的选择这是位于在这里工作的GitHub上。出于某种原因,我能得到使用$范围语法时,选定的项目,而不是当我用控制器的语法。我想的plunker得到与控制工作作为语法位于这里。我不知道我失踪特别是自$范围语法完美的作品。
我没有得到任何错误报告。下面是从什么是plunker片段。
控制器
VAR应用= angular.module('示范',['ngSanitize','ui.select']);
app.controller(MainCtrl,MainCtrl);
函数MainCtrl()
{
VAR控制器=这一点; controller.person = {};
controller.people = [
{名称:'亚当',电子邮件:adam@email.com',年龄:10},
{名称:'利亚',电子邮件:amalie@email.com',年龄:12},
{名:弗拉基米尔,电子邮件:wladimir@email.com',年龄:30},
{名:萨曼莎,电子邮件:samantha@email.com',年龄:31},
{名称:'埃斯特法尼亚',电子邮件:estefanía@email.com',年龄:16},
{名称:'娜塔莎',电子邮件:natasha@email.com',年龄:54},
{名称:'妮可',电子邮件:nicole@email.com',年龄:43},
{名称:'阿德里安',电子邮件:adrian@email.com',年龄:21}
];}
的index.html
<机身NG控制器=MainCtrl为VM>
< H3>选择二主题和LT; / H3 GT&;
< P>选择:{{vm.person.selected}}< / P>
< UI选NG模型=person.selected.name主题=选择2NG-禁用=残疾的风格=最小宽度:300像素;>
< UI的选择匹配占位=,在列表中选择一个人或者搜索自己的名字/年龄......> {{$ select.selected.name}}< / UI选匹配>
< UI的选择,选择重复=人vm.people | propsFilter:{名:$ select.search,年龄:$ select.search}>
< DIV NG绑定-HTML =person.name |亮点:$ select.search>< / DIV>
<小>
电子邮件:{{person.email}}
年龄:LT;跨度NG绑定-HTML =''+ person.age |亮点:$ select.search>< / SPAN>
< /小>
< / UI的选择,选择>
< / UI选>
固定所有脚本后与 HTTPS
工作,而不是 HTTP
(对于plunker要求)和不断变化的 NG-模式=person.selected.name
到 NG-模式=VM .person.selected.name
中,ControllerAs版本的作品完美,没有进一步的调整。
https://plnkr.co/edit/2VtUefWPKdBVaqY1gU66?p=$p$ PVIEW
I'm trying to get a select HTML control working with AngularJS ui-select which is located here on GitHub. For some reason, I am able to get the item selected when using $scope syntax, but not when I use the Controller As syntax. The plunker I am trying to get working with Controller as syntax is located here. I'm not sure what I am missing especially since the $scope syntax works perfectly.
I'm not getting any errors to report. Here is a snippet from what is in plunker.
Controller
var app = angular.module('demo', ['ngSanitize', 'ui.select']);
app.controller("MainCtrl", MainCtrl);
function MainCtrl()
{
var controller = this;
controller.person = {};
controller.people = [
{ name: 'Adam', email: 'adam@email.com', age: 10 },
{ name: 'Amalie', email: 'amalie@email.com', age: 12 },
{ name: 'Wladimir', email: 'wladimir@email.com', age: 30 },
{ name: 'Samantha', email: 'samantha@email.com', age: 31 },
{ name: 'Estefanía', email: 'estefanía@email.com', age: 16 },
{ name: 'Natasha', email: 'natasha@email.com', age: 54 },
{ name: 'Nicole', email: 'nicole@email.com', age: 43 },
{ name: 'Adrian', email: 'adrian@email.com', age: 21 }
];
}
index.html
<body ng-controller="MainCtrl as vm">
<h3>Select2 theme</h3>
<p>Selected: {{vm.person.selected}}</p>
<ui-select ng-model="person.selected.name" theme="select2" ng-disabled="disabled" style="min-width: 300px;">
<ui-select-match placeholder="Select a person in the list or search his name/age...">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="person in vm.people | propsFilter: {name: $select.search, age: $select.search}">
<div ng-bind-html="person.name | highlight: $select.search"></div>
<small>
email: {{person.email}}
age: <span ng-bind-html="''+person.age | highlight: $select.search"></span>
</small>
</ui-select-choices>
</ui-select>
After fixing all of your scripts to work with https
rather than http
(requirement for plunker) and changing ng-model="person.selected.name"
to ng-model="vm.person.selected.name"
, the ControllerAs version works perfectly with no further adjustments.
https://plnkr.co/edit/2VtUefWPKdBVaqY1gU66?p=preview
这篇关于Angularjs UI的选择(选择2)不与“控制器”语法工作没有得到选择伊特的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!