2014-12-04 27 views
-1

我想导入在外部控制器作用域中声明的模板文件。我如何获得标签中的HTML代码?如何在Angular.JS指令中导入模板?

JS例

app.directive('memberList', function ($compile,$templateCache) { 

     .. 
     link : function(scope, element){   
     /* 
      I'd like to bring in this section are declared 
      in the html script tag(listMemberTmp). 
     */ 

     }; 
     .. 
    }); 

HTML Exmplate。

<div member-list></div> 


<script type="text/ng-template" id="listMemberTmp">  
html code 

</script> 

回答

0

为什么不直译?

HTML:

<div member-list> 
    html code 
</div> 

JS:

app.directive('memberList', function ($compile,$templateCache) { 
    .. 
    transclude: true 
    .. 
}); 

编号:https://docs.angularjs.org/guide/directive

请参阅:创建一个包装其他元素

一个指令