我在控制器中使用ui-select,我需要从控制器中监听ng-model的更改,这是我的HTML:
<div id="countryCtrl" country-selection class="form-inline">
<ui-select ng-model="selectedCountry" theme="selectize" style="{{$cat_style}}">
<ui-select-match placeholder="Select or search ...">
@{{$select.selected.title}}
</ui-select-match>
<ui-select-choices repeat="country in countries | filter: $select.search">
<span ng-bind-html="country.title | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
</div>
在countrySelection控制器中:
angular.module('mainCtrl').directive('countrySelection', ['Country','state', function(Country, state) {
var linkF = function (scope, element, attrs, widgetPath) {
scope.$watch("selectedCountry", function (neww, old) {
console.log(scope.selectedCountry);
widgetPath.selectedCountry= widgetPath.model.selectedCountry;
scope.update("state.country.changed",scope.selectedCountry);//widgetPath.model.selectedCountry);
}, true);
};
return {
require: "^widgetPath",
restrict: 'A',
link: linkF,
scope: {}
}
}]);
如果我将ui-select指令的国家/地区选择设置为这样的属性,watch会起作用:
<ui-select ng-model="selectedCountry" country-selection theme="selectize" style="{{$cat_style}}">
但是,我将无法隔离country-selection
的范围,我将收到错误
Multiple directives [countrySelection, uiSelect] asking for new/isolated scope on:
那么,我如何在父指令ng-Model
的{{1}}指令中查看ui-select
属性?
答案 0 :(得分:0)
有on-select属性,您可以在其中调用范围内的函数。
<ui-select ng-model="person.selected" theme="select2" on-select="someFunction($item, $model)" ...