У меня есть директива, которая берет в коллекции и выстраивает выпадающий список.ui-select2 inside директива не обновляет модель контроллера
.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;
, но это по-прежнему быть первым item EVEN, хотя я обновил раскрывающееся меню, которое, согласно функции часов, изменилось на правильное значение. Что мне здесь не хватает?