2015-09-30 55 views
0

我已經有一個指令(appView),並且有一些html可以通過templateUrl加載。到目前爲止,我需要向另一個指令(appView)正在使用的模板添加一個自定義指令。如何將自定義指令包含在角度js中的另一個自定義指令的模板(html)

請參閱下面的代碼,它不按預期工作。有關這方面的任何幫助,我可以如何讓這項工作?

View.html(模板)

<div> 
    <div class="dragdrop" id="dropzone" dropzone> //here is my custom directive 
     <div class="fileUpload btn btn-primary"> 
     <span>UPLOAD ASSETS</span> 
     <input id="dzFile" type="file" class="upload" /> 
     </div> 
    </div> 
</div> 

角JS

var appModule = angular.module("Newapp", []); 

appModule.directive("appView", appView); 
function appView(){ 
    var directive = { 
     restrict: 'E', 
     templateUrl: 'app/View.html' 
    }; 
    return directive; 
} 

appModule.directive("dropzone", function(){ //This is added to the View.html as attribute(see above html code with **) 
    var directive = { 
     restrict: 'A', 
     link: FullDragDrop 
    }; 
    return directive; 
}); 

function FullDragDrop(){ 
    console.log("soemthing goes here"); 
} 

我怎樣才能使這個可能,請?

+0

爲什麼** **懸浮窗,而不是你的懸浮窗裏面View.html? – Nicolas2bert

+0

@NicolasHumbert,這是通知誰引用,多數民衆贊成它。它只是dropzone – User123

+0

@ User123你在找什麼?你的代碼正在工作。你可以檢查一下這個笨蛋,看看。顯示文字「這裏有東西」。 http://plnkr.co/edit/vwIrM7D402juEDDHDKbC?p=preview –

回答

0

此代碼適用於我。 確保templateUrl: '應用程序/ View.html'存在

<script> 

var appModule = angular.module("Newapp", []); 

    appModule.directive("appView", appView); 

     function appView(){ 

      var directive = { 
       restrict: 'E', 
       templateUrl: 'view.html' 
      }; 

      return directive; 

     } 



    appModule.directive("dropzone", function(){ //This is added to the View.html as attribute(see above html code with **) 


     var directive = { 
       restrict: 'A', 
       link: FullDragDrop 
      }; 

      return directive; 

    }); 




    function FullDragDrop(){ 

     console.log("soemthing goes here"); 

    } 


</script> 

<script type="text/ng-template" id="view.html"> 
    <div class="dragdrop" id="dropzone" dropzone> //here is my custom directive 
      <div class="fileUpload btn btn-primary"> 
      <span>UPLOAD ASSETS</span> 
      <input id="dzFile" type="file" class="upload" /> 
      </div> 
     </div> 
</script> 

<body> 
    <app-view></app-view> 
</body> 
相關問題