angularjs ng-app

來源:互聯網
上載者:User

標籤:

<!DOCTYPE HTML><html ng-app>    //ng-app是初始化指令,整個頁面都會被angularjs解析,寫在div或者其他標籤上表示只是局部的div和標籤裡面使用angularjs解析,其餘的不用anguarjs解析。<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>無標題文檔</title><script src="angular.min.js"></script><script>function Aaa($scope,$timeout){    $scope.name = ‘hello‘;    setTimeout(function(){        $scope.name = ‘hi‘;//setTimeout這個定時器不能重新整理name的值    },2000);    $timeout(function(){        $scope.name = ‘hi‘;//$timeout是angularjs的定時器才能使name值重新整理    },2000);        $scope.show = function(){        $scope.name = ‘hi‘;    };    }</script></head><body>//ng-controller是控制器<div ng-controller="Aaa" ng-click="name=‘hi‘">  click函數改變name的值<div ng-controller="Aaa" ng-click="show()">     作用同上    <p>{{name}}</p></div></body></html>
<!DOCTYPE HTML><html ng-app><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>無標題文檔</title><script src="angular.min.js"></script><script>function Aaa($scope,$timeout){    $scope.name = ‘hello‘;}</script></head><body><div ng-controller="Aaa">    <input type="text" ng-model="name">    輸入框改變標籤p也改變。    <p>{{name}}</p></div></body></html>

 

<!DOCTYPE HTML><html ng-app><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>無標題文檔</title><script src="angular.min.js"></script><script>function Aaa($scope,$timeout){    $scope.iphone = {        money : 5,        num : 1,        fre : 10    };    $scope.sum = function(){        return $scope.iphone.money * $scope.iphone.num;    };        /*$scope.$watch(‘iphone.money‘,function(newVal,oldVal){        console.log(newVal);        console.log(oldVal);    },true);*/        $scope.$watch($scope.sum,function(newVal,oldVal){ //$watch監聽資料的變化        //console.log(newVal);        //console.log(oldVal);        $scope.iphone.fre = newVal >= 100 ? 0 : 10;    });}</script></head><body><div ng-controller="Aaa">    <p>價格:<input type="text" ng-model="iphone.money"></p>    <p>個數:<input type="text" ng-model="iphone.num"></p>    <p>費用:<span>{{ sum() | currency:‘¥‘ }}</span></p>  currency是過濾器    <p>運費:<span>{{iphone.fre | currency:‘¥‘}}</span></p>    <p>總額:<span>{{ sum() + iphone.fre | currency:‘¥‘}}</span></p></div></body></html>

 

angularjs ng-app

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.