ui-select封装在一个指令中

时间:2015-10-15 07:53:45

标签: ui-select

我试图将特定于我的项目的一些内容抽象为构建在ui-select之上的指令。我遇到了一个基本问题,即ui-select指令不响应我的指令中的任何范围更改。

奇怪的是,在我的指令中观察相同的变量显示值确实在变化。

这是最精简的羽毛球:http://plnkr.co/edit/8J3aMK1YMIIsJC3oa56U

感谢任何帮助。

'use strict';

var app = angular.module('demo', ['ngSanitize', 'ui.select']);

app.controller('DemoCtrl', function($scope, $http, $timeout) {
  $scope.multipleDemo = {};
  $scope.disabled = undefined;

  $scope.enable = function() {
    $scope.disabled = false;
  };

  $scope.disable = function() {
    $scope.disabled = true;
  };
});

app.directive('tagEditor', [function() {
  return {
    restrict: 'A',
    //replace: true,
    templateUrl: 'tagEditor.html',
    scope: {
      isDisabled: '@',
      tags: '='
    },
    link: function(scope, elem, attrs) {
      scope.$watch('isDisabled', function(newVal, oldVal) {
        console.log('isDisabled watch fired with values ' + newVal + ',' + oldVal);
        console.log('isDisabled value is ' + scope.isDisabled + ' and type is ' + typeof scope.isDisabled);
      });

      scope.$watch('tags', function(newVal, oldVal) {
        console.log('tags watch fired with values ' + newVal + oldVal);
      });
    }
  };
}]);

0 个答案:

没有答案