Angularjs Practice Demo1

Source: Internet
Author: User

@{Layout=NULL;}<! DOCTYPE html>varApp = Angular.module ("myApp", []); App.controller ("Firstcontroller",function($scope, $timeout) {setTimeout (function () {                //$scope. Name = "111";//This will not change the value of name after two seconds$scope. $apply (function() {//using some external methods (such as js,jquery) to make the model change we need to use the $apply: the usage is to put the external method to execute in $apply ()$scope. Name = "111";            }); }, 2000); $scope. Name= "Zhang San"; $scope. Age= 10; $scope. Show=function() {$scope. Name= "Click me Now"; } $timeout (function() {$scope. age= "50"; }, 2000);        }); App.controller ("Secondcontroller",function($scope) {$scope. iphone={money:15, Num:1, Fre:10            }; $scope. Sum=function () {                return$scope. Iphone.money *$scope. Iphone.num;            }; $scope. $watch ($scope. Sum,function(NewValue, OldValue) {//monitor changes in $scope.sum$scope. Iphone.fre = newvalue >= 100? 0:10;        });    }); </script>changes in the model of $apply propagation$watch Monitor the model changes{{name}}<br/>{{Age}}</div> <div ng-controller= "Secondcontroller" > <p> Price: <input type= "text" ng-model= "IP            Hone.money "/></p> <p> number: <input type=" text "ng-model=" Iphone.num "/></p> <p> Fee: <span>{{sum () | Currency: ' ¥ '}}</span></p> <p> shipping: <span>{{iphone.fre | Currency: ' ¥ '}}</span></p> <p> total: <span>{{sum () +iphone.fre | currency: ' ¥ '}}</span>& Lt;/p> </div> </div></body>

Angularjs Practice Demo1

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.