所以我想用我的配置创建一个嵌入了角度ui-select指令的指令。 但是,当我将变量传递给ng-model时,它不会在父项中更新。只有在ui-select本身。我假设在隔离范围内调用'='会导致双向数据绑定。我必须在某个地方拨打$ apply吗? 有什么帮助吗?
所以我的html用法应该是这样的:
<interpreter-search ng-model="booking.interpreterId" id="field_interpreter"/>
指令:
angular.module('omserviceApp')
.directive('interpreterSearch', ['InterpreterSearch' , function (InterpreterSearch) {
return {
restrict: 'E',
scope:{
interpreterId: '=ngModel'
},
link: function (scope, element, attrs) {
scope.refreshInterpreters = function (query) {
InterpreterSearch.query({query: query}, function (result) {
scope.interpreters = result;
}, function (response) {
if (response.status === 404) {
scope.interpreters = [];
}
});
};
},
templateUrl: 'scripts/components/entities/interpreter/interpreter-search.html'
}
}]);
模板:
<ui-select ng-model="interpreterId">
<ui-select-match placeholder="Find an interpreter...">
<span ng-bind="interpreterId"></span>
</ui-select-match>
<ui-select-choices repeat="interpreter.id as interpreter in (interpreters | filter: $select.search)"
refresh="refreshInterpreters($select.search)"
refresh-delay="0">
<span ng-bind="interpreter | interpreterHtml"></span>
</ui-select-choices>