Javascript Angularjs-$scope.$destroy不';不要移除观察者
我正试图找出如何创建我自己的“一次性绑定”,对于Angularjs使用Javascript Angularjs-$scope.$destroy不';不要移除观察者,javascript,angularjs,angularjs-scope,Javascript,Angularjs,Angularjs Scope,我正试图找出如何创建我自己的“一次性绑定”,对于Angularjs使用cleanup函数删除观察者: function cleanup(element) { element.off().removeData(); var injector = currentSpec.$injector; element.$injector = null; // clean up jquery's fragment cache angular.forEach(angular.el
cleanup
函数删除观察者:
function cleanup(element)
{
element.off().removeData();
var injector = currentSpec.$injector;
element.$injector = null;
// clean up jquery's fragment cache
angular.forEach(angular.element.fragments, function(val, key) {
delete angular.element.fragments[key];
});
angular.forEach(angular.callbacks, function(val, key)
{
delete angular.callbacks[key];
});
angular.callbacks.counter = 0;
}
使用自毁服务作为简单绑定一次:
function onetime()
{
/*...*/
onetime = Function;
}
angular.module('myApp').constant('bindonce', onetime);
angular.module('myApp').controller('foo', function($bindonce){
this.$inject = '$bindonce';
$scope.mybind = $bindonce();
}
请参考迁移指南以查找突破性更改:
参考资料
function onetime()
{
/*...*/
onetime = Function;
}
angular.module('myApp').constant('bindonce', onetime);
angular.module('myApp').controller('foo', function($bindonce){
this.$inject = '$bindonce';
$scope.mybind = $bindonce();
}