码迷,mamicode.com
首页 > 移动开发 > 详细

angularjs ng-app

时间:2016-08-03 23:38:51      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

<!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

标签:

原文地址:http://www.cnblogs.com/yaowen/p/5734702.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!