2014-03-13 77 views
0

如何使用角度來實現類似以下的內容?我試過幾種技術,但文檔不太多幫助...angularjs:實時指令

<div id="#parent"> 
    <!-- this is component definition, won't be rendered --> 
    <component id="tbl"> 
    <table> 
     <tbody> 
     <tr ng-repeat="item in env.items"><td>{{item.label}}</td></tr> 
     <tbody> 
    </table> 
    </component> 

    ... 
    <!-- 
    this should only work if a component is registered within this parent, 
    ie '#parent' and would render the component as defined above 
    --> 
    <component ref="table" env="myCtx" /> 
</div> 

控制器會是這樣的:

<script> 
//ctrl definition 
funcion Ctrl(scope) { 
    scope.myCtx = { 
    items: [{label: "xxx"}, {label: "yyy"}] 
    } 
} 
</script> 

基本上,我要定義一個指令上的-fly,我希望它只能在#parent節點內訪問(儘管這是可選的)。我被卡住了,因爲我希望能夠在compile函數或transclude函數中注入角度感知 html(即,<h1>{{blah}}</h1>)。

回答

0

有時候你不得不從頭開始自己的癢:http://jsfiddle.net/mping/6fwJ3/11/

最終採取了不同的路線。我使用父母controller和兩個指令,一個用於定義組件,另一個用於調用它。