我有一个指令,需要一个集合并构建一个下拉列表。ui-select2里面的指令没有更新控制器模型
.directive("lookupdropdown", function() {
return {
restrict: 'E',
scope: {
collectionset: '=',
collectionchoice: '='
},
replace: true,
template: '<select class="input-large" ui-select2 ng-model="collectionchoice" data-placeholder="">' +
' <option ng-repeat="collection in repeatedCollection" value="{{collection.id}}">{{collection.description}}</option>' +
'</select>',
controller: ["$scope", function ($scope) {
$scope.repeatedCollection = new Array(); //declare our ng-repeat for the template
$scope.$watch('collectionset', function() {
if ($scope.collectionset.length > 0) {
angular.forEach($scope.collectionset, function (value, key) { //need to 'copy' these objects to our repeated collection array so we can template it out
$scope.repeatedCollection.push({ id: value[Object.keys(value)[0]], description: value[Object.keys(value)[1]] });
});
}
});
$scope.$watch('collectionchoice', function (newValue, oldValue) {
debugger;
$scope.collectionchoice;
});
} ]
}
});
这工作正常。它构建出下降没有问题。当我改变下拉值时,第二个监视函数被调用,我可以看到它将集合选择的值设置为我想要的值。但是,我已经将这些收集选项放入指令中并不会影响新的选择。
<lookupDropdown collectionset="SecurityLevels" collectionchoice="AddedSecurityLevel"></lookupDropdown>
这是HTML标记。
这是JavaScript:
$scope.SecurityLevels = new Array();
$scope.GetSecurityLevelData = function() {
genericResource.setupResource('/SecurityLevel/:action/:id', { action: "@action", id: "@id" });
genericResource.getResourecsList({ action: "GetAllSecurityLevels" }).then(function (data) {
$scope.AddedSecurityLevel = data[0].SCRTY_LVL_CD;
$scope.SecurityLevels = data;
//have to get security levels first, then we can manipulate the rest of the page
genericResource.setupResource('/UserRole/:action/:id', { action: "@action", id: "@id" });
$scope.GetUserRoles(1, "");
});
}
$scope.GetSecurityLevelData();
然后,当我去后我的新用户角色,我这样设置用户角色字段:
NewUserRole.SCRTY_LVL_CD = $scope.AddedSecurityLevel;
,但是这仍然是第一尽管我已更新下拉菜单,但根据手表功能,它已更改为正确的值。我在这里错过了什么?