标签:技术 hone images ima rip script button lis fas
这里使用的是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); } }
效果:
标签:技术 hone images ima rip script button lis fas
原文地址:http://www.cnblogs.com/sweng/p/6371701.html