2015-10-14 135 views
2

我有一个自定义指令,我已经创建了一个模板加载到模态窗口。模态窗口本身就是一个模板,并且能够运行我的自定义指令而没有问题。加载到模式中的模板包含使用angular-selectize创建选择列表的另一个指令。这是我的指令:嵌套指令不编译

var dynamicTemplate = function($templateRequest, $compile) { 

    return { 
     restrict: "E", 

     link: function(scope, element, attrs) { 

     var modalOptions = JSON.parse(attrs.modalOptions); 

     $templateRequest(modalOptions.Url).then(function(html) { 

      $elem = $compile(html)(scope); 
      element.append($elem); 
     }); 

     } 
    } 
    } 

HTML正在正确加载,但selectize指令未初始化。

我也厌倦了这样的then方法中:

element.html(html) 
$compile(element.contents())(scope); 

这给了我同样的结果。

我遇到的问题是,我的HTML的编译后收到此消息:

TypeError: element.selectize is not a function 

这里是the plunk我一起工作。

回答

2

如果你想要angular.element使用jQuery,你必须在角度加载之前在页面中包含jQuery。一旦更改脚本命令

演示工作正常

Updated demo

2

首先解决

你Angular.js index.html中之前包含的jquery.js。这魔术使angular.element使用jQuery。
Solution 1

解决方法二

您可以在角selectize.js与$(element).selectize取代element.selectize上线97这使得角selectize脚本改为使用角度的的jQuery的选择。
Solution 2

0

在Angular载入之前在页面中包含jQuery。然后angular.element将使用jQuery。

+0

我不明白倒票。 – superczan