码迷,mamicode.com
首页 > 其他好文 > 详细

Controllers的使用

时间:2016-05-24 18:51:20      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

代码

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"
})

  

Controllers的使用

标签:

原文地址:http://www.cnblogs.com/yedushusheng/p/5524241.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!