HTML:
<br/><button class="btn btn-primary" ng-disabled="enableCompare()" ng-click="on_compare_plateformes($item)">Comparer</button>JS:
propertiesModule.controller('PropertiesComparePlateformesCtrl', ['$scope', 'compareService', '$routeParams', 'PropertiesService', 'ApplicationService', 'PlatformService', 'Page', function ($scope, compareService, $routeParams, PropertiesService, ApplicationService, PlatformService, Page) {
$scope.on_compare_plateformes = function () {
...
};
..
}]);
propertiesModule.directive('propertiesListCompare', ['compareService', function (compareService) {
return {
restrict: 'E',
scope: {
properties: '=',
propertiescible: '=',
application: '=',
applicationcible: '=',
undo: '=',
myselectref: '=',
myselectcible: '='
},
templateUrl: "properties/properties-list-compare.html",
link: function (scope, element, attrs) {
// scope.$watch("propertiescible", function () {
var unregister = scope.$watch('[properties, propertiescible]',function () {
...
}, true);
...
unregister();
}
};
}]);当我点击我的按钮时,如何重新绑定$watcher。
发布于 2014-11-27 15:44:13
我想,通过调用unregister函数,您想要解除侦听器的绑定。但是当范围被破坏时,你应该这样做,而不是在观察者被设置之后。所以,
link: function (scope, element, attrs) {
var unregister = scope.$watch('[properties, propertiescible]', function () {
// do stuff
}, true);
scope.$on('$destroy', unregister);
}发布于 2015-12-05 08:15:21
若要在解除绑定后再次绑定监视程序,您需要再次调用$watch,除了此之外,没有安古拉杰再次绑定的方法。为此,您可以创建一个函数:
function watchProps(){
return scope.$watch('[properties, propertiescible]', function () {
..
}, true);
}然后将返回的去注册函数保存到变量中。
var deWatchProps = watchProps();又要看了就打电话给
var deWatchProps = watchProps();还可以创建如下所示的切换函数:
function toggleWatchProps(){
if(scope.watchProps)
{
scope.watchProps();
}
else{
scope.watchProps = scope.$watch('[properties, propertiescible]', function () {
..
}, true);
}
}https://stackoverflow.com/questions/27173556
复制相似问题