[英]Is there a Ready function for ng-bind-html in AngularJS?
I'm using ng-bind-html of AngularJS. 我正在使用AngularJS的ng-bind-html。 I have to initialize a plugin after my Binding function is over.
我的绑定功能结束后,我必须初始化一个插件。 So I would like to know if there is a method or a function to do that work ?
所以我想知道是否有一种方法或函数可以完成这项工作?
Thanks for you answers ! 谢谢您的回答!
One way you can do this is initialise a $watch
event over the variable you are using in your 'ng-bind'. 一种实现方法是在“ ng-bind”中使用的变量上初始化
$watch
事件。 Let m explain: 让m解释:
Suppose you have a span with an ng-bind like this: 假设您有一个带有ng-bind的跨度,如下所示:
<span ng-bind="val"></span>
Now, 'ng-bind' works in a way that whenever 'val' changes(within the digest cycle) it updates the value of the span, that is, it keeps a 'watch' on the 'val'. 现在,“ ng-bind”以一种方式工作,只要“ val”发生变化(在摘要周期内),它就会更新跨度的值,也就是说,它会在“ val”上保持“监视”状态。 Similarly, we can use our own watch on the 'val' in the controller like this:
同样,我们可以在控制器的“ val”上使用自己的手表,如下所示:
$scope.val; //your binded variable
$scope.$watch('val', function(newval, oldval) {
//here you can initialise your plugin and also access the old and new values of 'val'
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.