SCOPE는 View Connection Controller로 특수 JavaScript 객체를 재생합니다. 범위에는 모델 데이터가 포함되어 있습니다. 컨트롤러에서 모델 데이터는 $ SCOPE 객체를 통해 액세스합니다.
<cript> var mainApp = Angular.Module ( "mainApp", []); mainapp.controller ( "shapecontroller", function ($ scope) {$ scope.message = "in Shape Controller"; $ scope.type = "shape";}); </script>다음은 위의 예에서 고려해야 할 중요한 문제입니다.
$ SCOPE는 생성자의 컨트롤러에 대한 메트릭을 결정하기 위해 첫 번째 매개 변수로 사용됩니다.
$ SCOPE.MESSAGE 및 $ SCOPE.TYPE는 HTML 페이지에서 사용하는 모델입니다.
ShapeController의 응용 프로그램 모듈의 컨트롤러를 반영하도록 모델의 값을 설정했습니다.
$ 범위에서 기능 함수를 정의 할 수 있습니다.
상속 범위
범위는 특정 컨트롤러입니다. 중첩 컨트롤러를 정의하면 컨트롤러 자식이 상위 제어 범위를 상속합니다.
<cript> var mainApp = Angular.Module ( "mainApp", []); mainApp.controller ( "shapecontroller", function ($ scope) {$ scope.message = "shape controller"; $ scope.type = "shape";}); mainApp.controller ( "CircleController", function ($ scope) {$ scope.message = "in circle 컨트롤러";}); </script>다음은 위의 예에서 고려해야 할 중요한 문제입니다.
ShapeController에서 모델의 값을 설정했습니다.
서브 컨트롤러 CircleController 메시지를 무시합니다. "메시지"내부의 컨트롤러 CircleController 모듈이 사용되면 메시지를 다시 작성하는 데 사용됩니다.
예
다음 예제는 위의 모든 지침을 보여줍니다.
testangularjs.html
<html> <head> <title> angular js 형태 </title> </head> <h2> Angularjs 샘플 애플리케이션 </h2> <div ng-app = "mainApp"ng-controller = "shapecontroller"> <p> {{message}} <br/> {type}} </p> <div. ng-controller = "CircleController"> <p> {{message}} <br/> <br/> {{type}} </p> </div> <script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min. mainApp = Angular.Module ( "MainApp", []); mainApp.controller ( "shapecontroller", function ($ scope) {$ scope.message = "shape controller"; $ scope.type = "shape";}); mainApp.controller ( "CircleController", function ($ scope) {$ scope.message = "in circle 컨트롤러";}); mainApp.controller ( "squarecontroller", function ($ scope) {$ scope.message = "square 컨트롤러"; $ scope.type = "square";}); </script> </body> </html>결과
웹 브라우저에서 Open TextAngularjs.html. 결과는 다음과 같습니다.
위는 AngularJS 범위 정보의 편집입니다. 우리는 향후 관련 정보를 계속 추가 할 것입니다. 이 웹 사이트를 지원 해주셔서 감사합니다!