[英]Why does the code work within <script> tag, but not in external .js file? 🤨
[英]Script that handles a tag that is within a angular template file does not work
我有这个巨大的代码,这里没有必要显示,但是他会操纵这个div:
<div data-calendar="true"></div>
找到这样的:
var calendar = $('[data-calendar]');
如果标签在我的主要角度布局文件中,则该脚本起作用,但是当标签在角度模板文件中时,该脚本根本不起作用。
如何解决? 我已经将此脚本放在角度脚本之后,以使角度脚本之前运行,但根本不起作用。
包括模板中的脚本将永远无法使用,您需要能够控制其运行时间,以便它在添加,替换div等任何摘要发生的任何时间运行。
在这种情况下,最好的方法是使用指令。
<div calendar></div>
.directive('calendar', function() {
return {
link: function (scope, element) {
element.jqCalendar(); // jQuery plugin should be avail here, if you included jQuery and the plugin before angular.
}
};
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.