What is the difference between '@' and '=' in directive scope in AngularJS?

問題:

I've read the AngularJS documentation on the topic carefully, and then fiddled around with a directive.我仔細閱讀了有關該主題的AngularJS文檔,然後擺弄了一條指令。 Here's the fiddle .這是小提琴

And here are some relevant snippets:這裏有一些相關的片段:

  • From the HTML :HTML

    <pane bi-title="title" title="{{title}}">{{text}}</pane>
  • From the pane directive:從窗格指令:

    scope: { biTitle: '=', title: '@', bar: '=' },

There are several things I don't get:有幾件事我沒有得到:

  • Why do I have to use "{{title}}" with '@' and "title" with '=' ?爲什麼我必須使用帶有'@' "{{title}}"和帶有'=' "title"
  • Can I also access the parent scope directly, without decorating my element with an attribute?我也可以直接訪問父作用域,而不用屬性裝飾我的元素嗎?
  • The documentation says "Often it's desirable to pass data from the isolated scope via expression and to the parent scope" , but that seems to work fine with bidirectional binding too.文檔說“通常需要通過表達式將數據從隔離範圍傳遞到父範圍” ,但這似乎也適用於雙向綁定。 Why would the expression route be better?爲什麼表達路線會更好?

I found another fiddle that shows the expression solution too: http://jsfiddle.net/maxisam/QrCXh/我發現了另一個顯示錶達式解決方案的小提琴: http : //jsfiddle.net/maxisam/QrCXh/


解決方案:

參考一: https://en.stackoom.com/question/wx63
參考二: https://stackoom.com/question/wx63
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章