angularjs的Controller as
<html ng-app="notesApp">
<head><title>Notes App</title></head>
<body ng-controller="MainCtrl as ctrl">
<form ng-submit="ctrl.submit()" name="myForm">
<input type="text"
name="uname"
ng-model="ctrl.user.username"
required
ng-minlength="4">
<span ng-show="myForm.uname.$error.required">
This is a required field
</span>
<span ng-show="myForm.uname.$error.minlength">
Minimum length required is 4
</span>
<span ng-show="myForm.uname.$invalid">
This field is invalid
</span>
<input type="password"
name="pwd"
ng-model="ctrl.user.password"
required>
<span ng-show="myForm.pwd.$error.required">
This is a required field
</span>
<input type="submit"
value="Submit"
ng-disabled="myForm.$invalid">
</form>
<script src="http://riafan.com/libs/angular.js"></script>
<script type="text/javascript">
angular.module('notesApp', [])
.controller('MainCtrl', [function() {
var self = this;
self.submit = function() {
console.log('User clicked submit with ', self.user);
};
}]);
</script>
</body>
</html>
ng-controller="MainCtrl as ctrl",允许数据可以在同一个页面的不同的controller之间自由穿梭。。。
Create a reference to this in our controller.
angular.module('app').controller('MainCtrl', function ($scope){
var self = this;
Remove $scope from our controller dependency, and use self instead of $scope.

angular.module('app').controller('MainCtrl', function (){
var self = this;
self.message = 'hello';
self.changeMessage = function(message){
self.message = message;
};
});
angularjs的Controller as的更多相关文章
- AngularJS 中 Controller 之间的通信
用 Angular 进行开发,基本上都会遇到 Controller 之间通信的问题,本文对此进行一个总结. 在 Angular 中,Controller 之间通信的方式主要有三种: 1)作用域继承.利 ...
- angularjs 的controller的三种写法
AngularJS 的controller其实就是一个方法,它有三种写法: 第一种: <pre name="code" class="javascript" ...
- Angularjs中controller的三种写法
在Angular中,Directive.Service.Filter.Controller都是以工厂方法的方式给出,而工厂方法的参数名对应着该工厂方法依赖的Service.angularjs中cont ...
- Angularjs之controller 和filter(四)
Controller组件(http://www.angularjs.cn/A00C) 在AngularJS中,控制器是一个Javascript函数(类型/类),用来增强除了根作用域以外的作用域实例的. ...
- 在AngularJS的controller外部直接获取$scope
为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/5560843.html ...
- angularJS的controller之间如何正确的通信
AngularJS中的controller是个函数,用来向视图的作用域($scope)添加额外的功能,我们用它来给作用域对象设置初始状态,并添加自定义行为. 当我们在创建新的控制器时,angularJ ...
- angularjs 外部调用controller中的方法
angular.element(document.querySelector('[ng-controller=mainCtrl]')).scope().viewGo('tab.VIPPay_Succe ...
- 【angularJS】Controller控制器
1. 定义 控制器(Controller)在AngularJS中作用是增强视图(View),AngularJS控制器是一个构造方法,用来向视图(View)中添加额外功能. ng-controller指 ...
- AngularJS-01.AngularJS,Module,Controller,scope
1.AngularJS 一个构建动态Web应用程序的结构化框架. 基于JavaScript的MVC框架.( MVC ---- Model(模型).View(视图).Controller(控制器) ) ...
- angularJS中controller的通信
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
随机推荐
- 为什么使彩色图变灰RGB的权重会固定(R:0.299 G:0.587 B:0.114)?
人眼对绿色的敏感度最高,对红色的敏感度次之,对蓝色的敏感度最低,因此使用不同的权重将得到比较合理的灰度图像.根据实验和理论推导得出以下数值 R: 0.299. G: 0.587. B: 0.114.
- SCRIPT7002: XMLHttpRequest: 网络错误 0x2efe, 由于出现错误 00002efe 而导致此项操作无法完成
google中带中文参数可能查询,但是在IE带中文参数不能查询:报如下错误 SCRIPT7002: XMLHttpRequest: 网络错误 0x2efe, 由于出现错误 00002efe 而导致此项 ...
- ES6 学习1
https://www.jianshu.com/p/287e0bb867ae 1,let表示变量.const表示常量.let和const都是块级作用域.一个在函数内部,一个在代码块内部: const ...
- php in_array()优化
开年首篇文章,后天上班了,正在调整状态.年前室友问我一段程序效率问题,刚好来研究下!该函数是关于判断域名字符串是否是单拼域名.双拼域名.三拼域名...多拼域名问题: //原始程序function pi ...
- Python高级特性:Python迭代、生成器、列表生成式
迭代 给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历称为迭代(Iteration). 在java和C语言中,迭代是通过循环list的下标来完成的,Pyth ...
- Android ComponentName的用法
ComponentName(组件名称)是用来打开其他应用程序中的Activity或服务的. 用法: Intent it=new Intent(); it.setComponent(new Compon ...
- Day22-中间件
1.中间件,在其它程序中,有的叫管道,有的叫http handler.下面是原生的中间件 2.自己也可以写中间件 2.1 写中间件,新建文件夹Middle,新建m1.py 2.2 在setting里注 ...
- WampServer3.0允许局域网访问配置教程
wamp server 下的Apache默认设置是不允许外网访问和局域网访问的,而直接搜索 wamp局域网访问配置,出现都是一些旧版本的wamp的配置信息,最新版本3.0.X需要使用以下配置方法: 配 ...
- python中文档IO的读写
首先明确一点,现代计算机的操作系统都不允许程序直接操作磁盘的,所以读取文件和写入文件都是有操作系统提供的提供的接口完成的,每一种编程语言都会把操作系统提供的低级C接口封装起来方便使用,Python也不 ...
- 【刷题】UOJ #207 共价大爷游长沙
火车司机出秦川,跳蚤国王下江南,共价大爷游长沙.每个周末,勤劳的共价大爷都会开车游历长沙市. 长沙市的交通线路可以抽象成为一个 \(n\) 个点 \(n−1\) 条边的无向图,点编号为 \(1\) 到 ...