-2
Q
継承は
A
答えて
1
雅が、これは本当にあまりにも私を混乱しました。だから、$スコープはありません。$ newが呼び出されます。つまり、ディレクティブがアクセスするスコープは親スコープです。これをスコープを共有するものと考えてください。
<div ng-controller="CtrlA">
<div ng-controller="CtrlB">
<my-directive></my-directive>
</div>
</div>
// In this example, the directive code's scope chain looks like this
// $rootScope --> CtrlA scope --> CtrlB scope
// So if our my-directive calls scope.doSomething()
// It looks in CtrlB first to see if that exists,
// because my-directive doesn't have its own scope
// Then it checks CtrlA, and finally $rootScope
// Standard prototypical inheritance
範囲:真
手段このディレクティブは、現在のスコープを継承し、独自のスコープを、望んでいます。 $ scope。$ newが呼び出され、現在のスコープが親として設定されます。スコープチェーンの仕組みです。
<div ng-controller="CtrlA">
<div ng-controller="CtrlB">
<my-directive></my-directive>
</div>
</div>
// In this example, the directive code's scope chain looks like this
// $rootScope --> CtrlA scope --> CtrlB scope --> my-directive scope
// So if our my-directive calls scope.doSomething()
// It looks in my-directive first to see if that exists
// Then it checks CtrlB, CtrlA, and finally $rootScope
// Standard prototypical inheritance
範囲:{}これは、単離されたスコープと呼ばれる
。隔離されたスコープは、継承チェーンなしで独自のスコープです。この指令は隔離されています。それは渡されたパラメータ(通常はディレクティブ要素の属性)にしかアクセスできず、コールバックを介してメッセージを送信する唯一の方法(属性としても設定されていますが、これらは面白い呼び出し方法があります)
<div ng-controller="CtrlA">
<div ng-controller="CtrlB">
<my-directive></my-directive>
</div>
</div>
// In this example, the directive code's scope chain looks like this
// my-directive scope
// So if our my-directive calls scope.doSomething()
// It only looks in my-directive to see if that exists
関連する問題
- 1. BuildManager継承の継承
- 2. クラス継承とインターフェイス継承
- 3. データ継承の継承
- 4. 継承は
- 5. ダイナミック継承は、
- 6. Hibernateは:継承
- 7. テンプレートを継承した継承継承メンバ
- 8. CSSが継承しない継承
- 9. 反復子継承と継承* this
- 10. C++多重継承/仮想継承
- 11. 継承 - ターゲット固有の継承クラスC#
- 12. Vector :: Vectorの継承継承クラス
- 13. Entity Frameworkとの継承継承
- 14. 継承する継承するインターフェイス
- 15. 継承したクラスを継承する
- 16. 継承継承について
- 17. Java ORM:複数(継承)継承
- 18. 継承
- 19. 継承
- 20. 継承
- 21. 継承
- 22. 継承
- 23. 継承
- 24. 継承
- 25. 継承
- 26. 継承
- 27. 人形は:継承
- 28. はジェネリックと継承
- 29. 継承コントローラメソッドはRequestMapping
- 30. テンプレートの継承は
問題の内容を説明してください。 –
http://www.undefinednull.com/2014/02/11/mastering-the-scope-of-a-directive-in-angularjs/ – Ajay