[英]Using a bindOnce directive with $http
I want to use the following bindOnce
directive: 我想使用以下bindOnce
指令:
.directive('bindOnce', function() {
return {
scope: true,
link: function( $scope, $element ) {
setTimeout(function() {
$scope.$destroy();
$element.removeClass('ng-binding ng-scope');
}, 0);
}
}
});
If I use this on a simple piece of html like so: 如果我像这样在一个简单的html上使用它:
<span class="highlight" data-bind-once> "{{listing.searchTerm}}"</span>
What happens is that there is nothing but the "" being displayed! 发生的事情是,除了显示“”外,什么都没有!
I am loading my data using the $http
service, I think the bind-once must get removed before I have loaded my data and then it obviously doesn't get bound. 我正在使用$http
服务加载数据,我认为必须先删除一次绑定,然后再加载数据,然后显然不会被绑定。
I want to use this in many places in my app, is this a limitation or am I doing this incorrectly? 我想在我的应用程序中的许多地方使用它,这是一个限制还是我做错了?
The newer versions of angular have the ability to bind once within them: 较新版本的angular可以在其中绑定一次:
<span class="highlight"> "{{ ::listing.searchTerm }}"</span>
Link: https://docs.angularjs.org/guide/expression#one-time-binding 链接: https : //docs.angularjs.org/guide/expression#one-time-binding
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.