首页 技术 正文
技术 2022年11月10日
0 收藏 446 点赞 4,256 浏览 2386 个字
 <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="/js/angular.min.js"></script>
<link href="/js/bootstrap-3.3.5-dist/css/bootstrap.min.css" rel="external nofollow" rel="stylesheet" />
<title>itcastNg</title>
<script>
(function (window) {
//此处的代码不会污染全局作用域
var myApp = window.angular.module('myApp', []);
myApp.controller('DemoController', function ($scope) {
$scope.value = 10;
$scope.doCalc = function () {
$scope.value *= 2;
};
$scope.phones = [
{
"name": "Nexus S",
"snippet": "Fast just got faster with Nexus S.",
"age": 0
},
{
"name": "Motorola XOOM™ with Wi-Fi",
"snippet": "The Next, Next Generation tablet.",
"age": 1
},
{
"name": "MOTOROLA XOOM™",
"snippet": "The Next, Next Generation tablet.",
"age": 2
}
]; }); myApp.controller('PhoneController', function ($scope, $http) {
/* phones.js json数据
[
{
"name": "Nexus S",
"snippet": "Fast just got faster with Nexus S.",
"age": 0,
"imageUrl": "/img/01.png",
"id":1
},
{
"name": "Motorola XOOM™ with Wi-Fi",
"snippet": "The Next, Next Generation tablet.",
"age": 1,
"imageUrl": "/img/02.png",
"id": 2
},
{
"name": "MOTOROLA XOOM™",
"snippet": "The Next, Next Generation tablet.",
"age": 2,
"imageUrl": "/img/03.png",
"id": 3
}
]
*/
//json/phones.js 换成上面的json
$http.get('/html/angular/json/phones.js').success(function (data) {
$scope.phones = data;
});
}); })(window); </script>
<style>
.red { color: red; }
</style>
</head>
<body>
<div class="container" ng-app="myApp">
<div class="row" ng-controller="DemoController">
<div class="col-md-12">
<input type="text" ng-model="value" />
<input type="button" ng-click="doCalc()" value="*2" /> <br />
<input type="checkbox" ng-model="v"><span ng-class="{'red':v}">v</span><br />
</div>
<div class="row">
<div class="col-md-6">
<ul>
<li ng-repeat="phone in phones">
{{phone.name}}
<p>{{phone.snippet}}</p>
</li>
</ul>
<p>Total number of phones: {{phones.length}}</p> </div> <div class="col-md-6">
<div>
<!--Sidebar content-->
Search: <input ng-model="query"> - <span>{{query}}</span> </div>
<div>
<!--Body content--> <ul>
<li ng-repeat="phone in phones | filter:query">
{{phone.name}}
<p>{{phone.snippet}}</p>
</li>
</ul>
</div>
</div>
</div> </div> <div class="row" ng-controller="PhoneController">
Search: <input ng-model="query">
Sort by:
<select ng-model="orderProp">
<option value="name">Alphabetical</option>
<option value="age">Newest</option>
</select> <ul>
<li ng-repeat="phone in phones | filter:query | orderBy:orderProp">
{{phone.name}}
<p>{{phone.snippet}}</p>
</li>
</ul>
</div>
<hr />
</div>
</body>
</html>

或者简单点…

  angular.module("myapp", [])
.controller("phoneController", function ($scope, $http, $location) {
//todo...
});
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,489
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290