我正在尝试编写一个指令,为带有ng-options的中时,项目会消失。
小例子:
html:
小例子:
html:
<div ng:app="editor" ng:controller="BaseController">
<select ng-model='m' ng-options='i.Id as i.Val for i in model.items' add-new-val='model.items'></select>
<select ng-model='m' ng-options='i.Id as i.Val for i in model.items'></select>
</div>
JavaScript:
var module = angular.module('editor', []);
function BaseController($scope){
$scope.model = {
items: [{Id:1, Val:"_1"}]
}
$scope.m = 1;
}
module.directive('addNewVal',function(){
return {
scope:{
items: '=addNewVal'
},
controller: function($scope){
$scope.items.push({Id: 3, Val: "Have a nice day"});
}
}
})
在jsfidle上。
有什么问题吗?