2.angular MVC

Source: Internet
Author: User
Tags angular scope

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.