angularJS学习笔记1

上传人:M****1 文档编号:492684308 上传时间:2023-04-10 格式:DOC 页数:7 大小:62KB
返回 下载 相关 举报
angularJS学习笔记1_第1页
第1页 / 共7页
angularJS学习笔记1_第2页
第2页 / 共7页
angularJS学习笔记1_第3页
第3页 / 共7页
angularJS学习笔记1_第4页
第4页 / 共7页
angularJS学习笔记1_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《angularJS学习笔记1》由会员分享,可在线阅读,更多相关《angularJS学习笔记1(7页珍藏版)》请在金锄头文库上搜索。

1、 demo Hello user.name clock clock1 name+.+username add Subtract Current count counter 姓名:person.name 年龄:person.age 地址:person.address 我是子控制域person.name parsedValue previewText $(function() ) /* app.js*/var current=new Date().getTime();function myController($scope,$timeout)var updateClock = function(l

2、asttime) $scope.clock = new Date().getTime(); 计时器clock每次都获取当前时间 $scope.clock1 = lasttime+1000; 计时器clock1用上一次的时间值+1000 $timeout(function() updateClock($scope.clock1); 将每次的clock1变量传入下一次updateClock中用于计时器clock1使用 ,1000); 你会发现定时1000毫秒这样计时是不准确的,所以在做时钟的时候不要使用这种计时器updateClock(new Date().getTime();angular.mo

3、dule(index,).run(function($rootScope)$rootScope.name=world;$rootScope.username=我XXXX;)var app=angular.module(index,);app.controller(firstController,function($scope , $parse, $interpolate)$scope.counter=0;$scope.person = /在firstController作用域中可以设置对象 name:Zheng Hang, age:25, address:北京$scope.add=functi

4、on(amount) $scope.counter += amount;$scope.subtract = function(amount) $scope.counter -= amount;$scope.$watch(expr,function(newVal,oldVal,scope) if(newVal != oldVal) /用该表达式设置parseFun var parseFun = $parse(newVal); /使用$parse这个内部服务来解析newVal /console.log(parseFun); /经过$parse服务函数处理过的表达式字符串变成了一个两个参数的函数 /

5、console.log(scope); /获取经过解析后表达式的值 scope.parsedValue=parseFun(scope) /给这个函数第一个参数传scope就能获取变量 )app.controller(secondController,function($scope)app.controller(thirdController,function($scope,$interpolate) /邮箱地址插入到正文使用$interpolate/设置监听$scope.$watch(emailBody,function(body) console.log(body); /我们可以从控制台中看

6、到我们输入textarea中的字符串 if(body) var template = $interpolate(body); /将我们输入到textarea中的模板字符串传给$interpolate它会返回一个设置模板参数的函数 $scope.previewText=template(to:$scope.to) /给这个函数传入参数,即可用设置的参数值替换掉模板中的变量名称 ););以下是控制台输出的parseFun的表述interpolate模板功能演示地址:http:/ console.log(newto); if(newto&$scope.emailBody) var template = $interpolate($scope.emailBody); $scope.previewText=template(to:newto) );

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号