2015-10-14 220 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