0

我的指令定义为:

angular.module('mainCtrl').directive('countryCtrl', ['$compile', 'Country', function($compile, Country) {

   return {
        require: "^widgetPath",
        restrict: 'E',
        scope:{
               selectedCountry: '='
        },
        link: function(scope, element, attrs, widgetPath) {

    scope.$watch("selectedCountry", function () {
                    alert ("this never get called");
                },true);
                console.log(widgetPath.model);
            }
        };
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<country-ctrl id="countryCtrl" 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>
    <p class="text-center" ng-show="loading"><span class="throbber"></span></p>

</country-ctrl>

当我更改所选国家/地区时,$watch无法正常工作,为什么?范围工作正常,因为 ng-show 工作正常。

我确信我缺少一些简单的东西,有人可以解释一下吗?

4

0 回答 0