2013-08-26 39 views
0

我正在學習角度,並且已經理解指令中的範圍,我開始更加......大膽,我應該說。我想呈現嵌套在另一個表格單元格中的表格,其中兩個表格由兩個具有不同作用域的獨立指令生成。 這裏的小提琴:
http://jsfiddle.net/jared_t83/Y8LjY/
這裏是有問題的鏈接方法:放置在另一個指令的link()方法中的指令不會渲染

link: function($scope, element, attrs) { 
    $scope.property = "scopingTest2.link() - won't overwrite parent" 
    var html = element.html(), 
    text = [ 
     'scopingtest2 - new scope, prototipically inherited from the parent', 
     '<table>', 
     '<tr><th>key</th><th>value</th></tr>', 
     '<tr>', 
     '<td>Nested table should be here: <br><div scoping-test1></div></td>', 
     '</tr>', 
     '<tr>', 
     '<td>$scope.property</td>', 
     '<td>', $scope.property, '</td>', 
     '</tr><tr>', 
     '<td> $scope.$parent.property </td>', 
     '<td>', $scope.$parent.property, '</td>', 
     '</tr><tr>', 
     '<td> $scope.__proto__.property</td>', 
     '<td>', $scope.__proto__.property, '</td>', 
     '</tr></table><br>' 
    ] 
    element.html(html + text.join('')); 
} 

線應該呈現嵌套表是:

 '<tr>', 
     '<td>Nested table should be here: <br><div scoping-test1></div></td>', 
     '</tr>', 

而是呈現的表我看到上面的文字。
我在做什麼錯?如何實現我想要的? 我很欣賞你的時間,
問候
賈裏德

回答

0

好吧,我現在明白了。

element.html(html + text.join('')); 

是一個jqLit​​e函數,它只是將傳遞的文本放在目標元素上。 爲了做我想做的事情,我需要使用angular指令的'template:'屬性。
傻我:)

相關問題