Controllers的使用
2016-05-24 17:35
330 查看
代码
angularjs.html <!doctype html> <html> <head> <meta charset="UTF-8"> <title>AngualrJS进阶</title> <link rel="stylesheet" type="text/css" href="css/foundation.css"> </head> <body style="padding:10px;" ng-app="app"> <div ng-controller="FirstCtrl"> <input type="text"ng-model="msg"> <h1>{{msg}}</h1> <br> <h1 ng-bind="msg"></h1> <!--可以使用ng-bind进行绑定,这样就不需要输入{{}}--> </div> <div ng-controller="SecondCtrl"> <input type="text" ng-model="msg"> <h1>{{msg}}</h1> <!--同样是msg,但是显示的不同这就是控制器作用域的问题,这个msg绑定的是SecondCtrl--> </div> </body> <script type="text/javascript" src="js/angular.js"></script> <script type="text/javascript" src="js/myctrl.js"></script> </html>
myctrl.js angular.module('app',[]) .controller('FirstCtrl',function($scope){ $scope.msg="hello angular"; }) .controller('SecondCtrl',function($scope){ $scope.msg="hello angularjs" })
相关文章推荐
- 5、Git本地分支与合并
- struts2的工作原理
- 前端跨域的整理
- PHP中XML和数组互相转换的方法
- windows-64位环境下搭建PHP5.5+Apache2.4+Mysql5.6+PhpMyAdmin
- android eclipse中html编辑器插件的下载和安装
- PHP中XML和数组互相转换的方法
- 创建响应式布局-图片、自适应与响应式
- 在$scope中变量和方法的使用
- 处理Xcode 警告
- Struts2的类型转换器
- Nginx Upstream负责均衡的实现方案
- 数据库之SQL的主键和外键的作用
- 集合框架-泛型
- itext导出word文档常用方法汇总
- JSOI2016酱油记
- Linux下的find指令详解
- Spring MVC详细运行流程
- js快速排序
- php mysql支持emoji表情方案