AngularJS学习(二)
来源:互联网 发布:动易cms模板免费下载 编辑:程序博客网 时间:2024/05/16 15:09
一、XHR的使用
1、何为XHR
XHR即为:XMLHttpRequest
使用xhr进行网络访问。var app=angular.module('app',[]); app.controller('Controller',function($scope,$http){ $scope.hello='hello,world!'; $http.get('../source/test.json').success(function (data){ $scope.phones=data; }); });当然,这里的“../source/test.json”只是一个URI地址,当然可以换成网络上的一个URI资源地址。
二、基本函数的使用
1、scope. watch
用于给一个module对象注册一个改变(change)的监听事件,当module改变的时候,触发一个函数。eg:
app.controller('StartUpController',function($scope){ $scope.start={hehe:0}; jisuan=function(){ $scope.start.haha=$scope.start.hehe*10; } $scope.$watch('start.hehe',jisuan); });当
start.hehe
发生改变的时候,就会触发jisuan
这个函数,将$scope.start.haha
的数值进行计算。
这里Dom元素的代码是:
<form ng-controller="StartUpController">
<input ng-model="start.hehe">
<hr />
result:{{start.haha}}
</form>
2、上面的事件的监听,同样可以使用ng-change
进行实现
app.controller('StartUpController',function($scope){ $scope.start={hehe:0}; $scope.jisuan=function(){ $scope.start.haha=$scope.start.hehe*10; } });DOM的代码是:
<form ng-controller="StartUpController">
<input ng-change="jisuan()" ng-model="start.hehe">
<hr />
result:{{start.haha}}
</form>仔细看的话,会发现两种方法,一个会写成
$scope.jisuan
,而一个是写jisuan=...
就行了,大概就是使用$scope.$watch
的方法中仅仅是给一个module进行事件的监听,而因为module的改变儿触发的jisuan这个函数不是归$scope
管理的,换言之:不需要在dom中进行controller;而第二种,需要进行ng-change
的绑定。
- AngularJS学习(二)
- AngularJS学习(二)
- angularJS学习笔记(二)
- AngularJS学习笔记(二)
- AngularJS学习笔记(二)
- angularJs学习笔记(二)
- AngularJS学习之路(二)AngularJS的表达式
- AngularJS 学习 (二)数据绑定
- angularJS学习之路(二)---模块
- angularjs学习5--过滤器(二)
- AngularJs学习笔记(二) 指令directive
- angularJs+MVC+C#学习(二)
- AngularJS学习总结系列(二)
- angularjs学习笔记(二)控制器1
- AngularJs学习之路(二)
- Angular学习(二)之AngularJS 表达式
- angularJS学习笔记二
- AngularJS学习(二) 引导
- java的单例模式
- STL源码剖析--内存分配器
- Spring boot 框架实用技巧(一)了解基本知识
- 关于一个嵌入dll程序集引发的血案
- 幂求模
- AngularJS学习(二)
- UVa 10562 看图写树
- Linux命令详解之三光盘加载及软硬链接
- Hadoop学习(3)----HDFS API
- html css javascript命名规范
- 2015 辽宁省赛G题 边权排序
- 超详细的vim+cscope 的使用规则 转载
- 高斯滤波器-这个我觉得讲的最好
- 自定义Dialog