javascript - Angularjs ui-select (select2) not working with 'Controller as' syntax not getting selected ite -
i'm trying select html control working angularjs ui-select located here on github. reason, able item selected when using $scope syntax, not when use controller syntax. plunker trying working controller syntax located here. i'm not sure missing since $scope syntax works perfectly.
i'm not getting errors report. here snippet 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 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 person in list or search 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 of scripts work https
rather http
(requirement plunker) , changing ng-model="person.selected.name"
ng-model="vm.person.selected.name"
, controlleras version works no further adjustments.
Comments
Post a Comment