angularjs MVC all with the help of $scope (scope) Implementation1.ng instruction
<!doctype html>
Getting objects from $scope
function Commoncontroller ($scope) {$scope. Commonfn=function () { alert ("This is a universal feature! "); };} function Controller1 ($scope) { $scope. Greeting = { text: ' Hello1 ' }; $scope. Test1=function () { alert ("Test1"); };} function Controller2 ($scope) { $scope. Greeting = { text: ' Hello2 ' }; $scope. Test2=function () { alert ("Test2");} }
2. Implement model<!doctype html>
1.NG-APP Specifies that the scope is Angularjs analytic ng-model can form Greeting.Text model object
3. Implement the View<!doctype html>
Using directive to achieve view reuse
var mymodule = angular.module ("MyModule", []) mymodule.directive ("Hello", function () { return { restrict: ' E ', Template: ' <div>hi everyone!</div> ', replace:true }});
$scope
- $scope is a pojp (Plain old JavaScript Object)
- $scope provides some tool methods $watch $apply
- $scope is the execution Environment (scope) of an expression
- $scope is a tree-like structure, parallel to the DOM tag
- The child $scope object inherits the properties and methods on the parent $scope
- Each angular application has only one root $scope object (typically located on Ng-app)
- $scope can propagate events, like DOM events, which can be up or down
- $scope is not only the basis of MVC, but also the basis for implementing bidirectional data binding later.
- Can be passed angular.element ($). Scope ()
- Debug plugin: Inspect Angular Scope (Chrome)
- Life cycle: Creation-watcher Registration-model mutation-mutation observation-scope Destruction
2.angular MVC