gpt4 book ai didi

javascript - ng-include 中使用的指令不起作用

转载 作者:行者123 更新时间:2023-11-28 19:19:42 26 4
gpt4 key购买 nike

我有如下自定义指令。

var fancySelectDirective = pluginDirecitvesModule.directive("custom-select",function(){
return {
restrict: 'C',
link: function (scope, element, attrs) {
element.fancySelect();
}
}
});

该指令在模板中使用。当我将此模板包含在 ng-include 中时,该指令不起作用,即未调用链接函数(我尝试在控制台中调试)。但是当我直接在 page 中使用此模板时,该指令有效。我找不到出现此问题的原因。

我使用 ng-include 如下:

<div id="main_wrapper" ng-include="template.html"></div>

该指令在模板中使用如下:

<select class="custom-select">

最佳答案

这只是一个拼写错误 customSelect 而不是 custom-select

指令应声明为驼峰式大小写,大写字母将替换为 - + 小写字母,例如。 customSelect 将在 html 上写为 custom-select

代码

var fancySelectDirective = pluginDirecitvesModule.directive("customSelect", function() {
return {
restrict: 'C',
link: function(scope, element, attrs) {
element.fancySelect();
}
}
});

希望对您有帮助,谢谢。

关于javascript - ng-include 中使用的指令不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29105655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com