2014-03-13 76 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和两个指令,一个用于定义组件,另一个用于调用它。