angularjs ng-app

<!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>
时间: 2024-11-10 00:15:17

angularjs ng-app的相关文章

AngularJs 开发app之准备工作3_gulp

写在前面的话: 常见的自动构建工具有 grunt.gulp.webpack,把源码进行合并压缩,节省带宽等~ 一起来学习 gulp 的使用吧~ 三.gulp的使用( gulp 中文网): gulp 的优点:基于流.任务化 常用API: src .dest .watch .task .pipe (1)安装 gulp: npm install -g gulp (2)再在 webapp文件夹下安装一些 nodejs 模块: npm init 之后webapp中就会出现一个package.json文件,

Part 15 AngularJS ng init directive

The ng-init directive allows you to evaluate an expression in the current scope. In the following example, the ng-init directive initializes employees variable which is then used in the ng-repeat directive to loop thru each employee. In a real world

Part 6 AngularJS ng repeat directive

ng-repeat is similar to foreach loop in C#. Let us understand this with an example. Here is what we want to do. 1. For each employee we have in the employees array we want a table row. With in each cell of the table row we to display employee Firstna

AngularJs 开发app之准备工作2_less

写在前面的话: less 可以实现 编程化的css,之前用过stylus,现在来学习下 less 有什么不一样的地方吧~ 二.css 预编译处理less(less中文网  , 在线编译工具) .less 文件,经过 less 工具,最后再转变成 .css文件 基础使用介绍: (1)关于变量 (2)关于函数 (3)关于引入其他less 文件 (4)关于选择器 后补~

[AngularJS - app] AngularJS Location-picker app

From: http://rangle.io/blog/two-ways-to-build-a-location-picker-for-a-mobile-angularjs-application/ Building mobile apps often requires working with location information. While, the Cordova geo-location plugin makes it quite trivial to get the latitu

Basics of AngularJS

Basics of AngularJS: Part 1 By Gowtham Rajamanickam on Apr 09, 2015 AngularJS I have planned to start writing about AngularJS. I have begun to learn AngularJS a few months back, it's a great feature for website UI developers. It is also easy to learn

angularjs源码分析之:angularjs执行流程

angularjs用了快一个月了,最难的不是代码本身,而是学会怎么用angular的思路思考问题.其中涉及到很多概念,比如:directive,controller,service,compile,link,scope,isolate scope,双向绑定,mvvm等.最近准备把这些都慢慢搞懂,分析源码并贴到博客园,如有分析不对的地方,还望各位包容并指正. angularjs源码分析之:angularjs执行流程 先上个大图,有个大概印象,注:angularjs的版本为:1.2.1,通过bowe

angularJS (2) angular.min.js

angular.min.js /* AngularJS v1.2.29 (c) 2010-2014 Google, Inc. http://angularjs.org License: MIT*/(function(V,W,v){'use strict';function z(b){return function(){var a=arguments[0],c,a="["+(b?b+":":"")+a+"] http://errors.a

ng 监听数据的变化

$scope.$watch('监听的变量的名称',func) 在angularJs之所以能够实现绑定,是因为angularJS框架在背后为每一个模型数据添加了一个监听,与$watch其实是一个道理. 结果: 代码: <html ng-app="myModule"> <head lang="en"> <meta charset="UTF-8"> <script src="js/angular.js

angularJS之$apply()方法

这几天,根据buddy指定的任务,要分享一点angular JS的东西.对于一个在前端属于纯新手的我来说,Javascript都还是一知半解,要想直接上手angular JS,遇到的阻力还真是不少.不过我相信,只要下功夫,即使是反人类的设计也不是什么大的问题.     Okay,废话不多说.为了弄明白angular JS为何物,我先是从Scope开始.那么什么是Scope呢?借用官方文档的一段话: "scope is an object that refers to the applicatio