我已經創建了一個父指令,它可以從給定的URL檢索數據,這很好。 作爲第二步,我要幾個孩子的指令,如之間的數據分發:具有子指令的父項在創建新的作用域時不起作用
<parent data="some/url/with/json/response">
<child data="data[0]"></child>
<child data="data[1]"></child>
...
</parent>
這也能正常工作。但是,在創建另一組指令時,舊數據會被覆蓋,因爲父指令不會創建新的作用域,而會覆蓋主作用域中的所有內容。當指定在該指令的下列行之一,沒有數據在所有示出(和現在錯誤味精出現):
scope: true,
//or
scope: {},
這裏的故障狀況的plunker例如:http://plnkr.co/edit/GWcLrhaUHNLPWNkOHIS8?p=preview 頂部部分應該有「這工作中」。
所以問題是:有誰知道我可以如何強制父指令創建一個新的範圍,所有子元素都可以訪問?
謝謝,現在這類作品,雖然 $ scope.data = $範圍$的eval($ attrs.data)。 是不是最好看的代碼;) – simP
我很抱歉,但我認爲它仍然無法正常工作,這個笨蛋顯示他們仍然有相同的範圍: http://plnkr.co/edit/22D9QMRA9gI4CmcAfJvz?p =預覽 – simP