Scopeは、View Connection Controllerとして特別なJavaScriptオブジェクトを再生します。スコープにはモデルデータが含まれています。コントローラーでは、モデルデータに$ Scopeオブジェクトを介してアクセスされます。
<script> var mainApp = angular.module( "mainapp"、[]); mainApp.Controller( "ShapeController"、function($ scope){$ scope.message = "in shapeコントローラー"; $ scope.type = "shape";}); </script>以下は、上記の例で考慮すべき重要な問題です。
$スコープは、コンストラクターのコントローラーのメトリックを決定する最初のパラメーターとして使用されます。
$ scope.messageおよび$ scope.typeは、HTMLページで使用するモデルです。
モデルの値を設定して、ShapeControllerのアプリケーションモジュールのコントローラーを反映しています。
$スコープで関数関数を定義できます。
継承範囲
範囲は特定のコントローラーです。ネストされたコントローラーを定義すると、コントローラーの子が親制御の範囲を継承します。
<script> var mainApp = angular.module( "mainapp"、[]); mainApp.Controller( "ShapeController"、function($ scope){$ scope.message = "in shapeコントローラー"; $ scope.type = "shape";}); MainApp.Controller( "Circlecontroller"、function($ scope){$ scope.message = "in circle controller";}); </script>以下は、上記の例で考慮すべき重要な問題です。
ShapeControllerにモデルの値を設定します。
SubController Circlecontrollerメッセージをオーバーライドします。 「メッセージ」内のコントローラーcirclecontrollerのモジュールが使用されると、メッセージは書き換えに使用されます。
例
次の例では、上記のすべての指示を示します。
testangularjs.html
<html> <head> <title> angular js forms </title> </head> <body> <body> <h2> angularjsサンプルアプリケーション</h2> <div-app = "mainapp" ng-controller = "shapecontroller =" shapecontroller " ng-controller = "circlecontroller"> <p> {{message}} <br/> {{type}} </p> </div> <script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"> Angular.module( "mainApp"、[]); mainApp.Controller( "ShapeController"、function($ scope){$ scope.message = "in shapeコントローラー"; $ scope.type = "shape";}); MainApp.Controller( "Circlecontroller"、function($ scope){$ scope.message = "in circle controller";}); mainApp.Controller( "SquareController"、function($ scope){$ scope.message = "in square controller"; $ scope.type = "square";}); </script> </body> </html>結果
WebブラウザでTextangularjs.htmlを開きます。結果は次のとおりです。
上記は、AngularJSスコープ情報の編集です。今後も関連情報を追加し続けます。このウェブサイトへのご支援ありがとうございます!