首页 > 其他 > 详细

Angular控制器

时间:2017-02-06 20:56:43      阅读:142      评论:0      收藏:0      [点我收藏+]

这里使用的是angular-1.0.1.min.js

Angular的前端渲染

<div>
	<ul>
		<li ng-repeat="i in [1,2,3]">
			<h1>{{i}}</h1>
		</li>
	</ul>
</div>

效果:

技术分享

使用控制器读取JSON:

<div ng-controller="PhoneListCtrl">
	<ul>
		<li ng-repeat="phone in phones">
			<h1>{{phone.name}}</h1>
			<p>{{phone.snippet}}</p>
		</li>
	</ul>
</div>

控制器代码:

function PhoneListCtrl($scope) {
	$scope.phones = [{
			"name" : "Nexus S",
			"snippet" : "Fast just got faster with Nexus S."
		}, {
			"name" : "Motorola XOOM with Wi-Fi",
			"snippet" : "The Next, Next Generation tablet."
		}, {
			"name" : "MOTOROLA XOOM",
			"snippet" : "The Next, Next Generation tablet."
		}
	];
}

效果:

技术分享

 

你也可以自己定义一个控制器:

<div ng-controller="mycontroller">
	<p>{{ article.ID }}</p>
	<p>{{ article.Name }}</p>
	<button ng-click="func()">测试</button>
</div>

控制器实现:

function mycontroller($scope) {
	$scope.article = {
		ID : 1,
		Name : "hell world"
	};
	$scope.func = function () {
		alert(1);
	}
}

效果:

技术分享

 

  

  

  

  

Angular控制器

原文:http://www.cnblogs.com/sweng/p/6371701.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!