angular.js规范写法
<!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="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...
});
angular.js规范写法的更多相关文章
- angular.js写法不规范导致错误
以下写法:没有明确指定module和controller,写法不规范. 更改angular.js版本会出bug. <html ng-app> <head> <title& ...
- Angular.js浅谈
至今博主对于MVVM框架比较了解的就只能算有Angular了,首先给大家明确一个概念,Angular1.x才能叫Angular.js,而Angular2.4.5都直接叫Angular了,因为从2开始已 ...
- Angular JS + Express JS入门搭建网站
3月份开始,接到了新的任务,跟UI开发有关,用的是Angular JS,Express JS等技术.于是周末顺便学习下新技术. 组里产品UI架构如下: 其中前端,主要使用Angular JS框架,另外 ...
- 学习angular.js的一些笔记想法(上)
1.data-ng-app与ng-app的区别 data-ng-app是为了h5不报错 2.ng-class 不多说就来拿例子说吧 html代码 <div class='color-change ...
- Angular.js+Bootstrap实现手风琴菜单
说是Angular.js+Bootstrap实现手风琴菜单,其实就是用了Bootstrap的样式而已. 上一篇实现了表格+分页,接着学习实现的Demo. 主要练习自定义指令,向指令中传递参数,老规矩先 ...
- angular.js——小小记事本3
app.js部分,首先是路由.这个之前讲过了,链接在这里—— http://www.cnblogs.com/thestudy/p/5661556.html var app = angular.modu ...
- angular.js之路由的选择
在一个单页面中,我们可以添加多个模块,使得网页只在需要的时候加载这个模块.模块的切换大致上可以代替网页的切换,于是,我们便可以通过模块的切换实现网页的切换,这个切换是按需加载的. 乍一看非常普通的东西 ...
- Angular.js之自定义指令学习笔记
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Angular.js学习笔记(三)
一.过滤器 1.uppercase,lowercase 大小写转换{{ "lower cap string" | uppercase }} // 结果:LOWER CAP STRI ...
随机推荐
- 链表&LRU
简介 链表就是链式存储数据的一种数据结构.双向链表每个数据存储都包含他的前后数据节点的位置信息(索引/指针). class DSChain<T> { //使用栈来进行废弃空间回收 priv ...
- 如何理解T-SQL中Merge语句
写在前面的话:之前看过Merge语句,感觉没什么用,完全可以用其他的方式来替代,最近又看了看Merge语句,确实挺好用,可以少写很多代码,看起来也很紧凑,当然也有别的优点. ====正文开始===== ...
- 说说SQL Server 网络配置
打开Sql Server Configuration Manager,里面显示了SQL Server的网络配置,这些到底表示什么含义呢? 图一:MSSQLSERVER的协议 这些配置选项,其实就是为了 ...
- 图解C#的值类型,引用类型,栈,堆,ref,out
C# 的类型系统可分为两种类型,一是值类型,一是引用类型,这个每个C#程序员都了解.还有托管堆,栈,ref,out等等概念也是每个C#程序员都会接触到的概念,也是C#程序员面试经常考到的知识,随便搜搜 ...
- 在Github上搭建自己的博客(Windows平台)
折腾了好久,终于在Github上搭建了自己的博客.这里面总结一下过程希望对大家能有所帮助. Github建博优缺点 和 csdn,新浪,网易相比,在Github上可以自己实现功能 和阿里云,VPS相比 ...
- Windows Azure Storage (6) Windows Azure Storage之Table
<Windows Azure Platform 系列文章目录> 最近想了想,还是有必要把Windows Azure Table Storage 给说清楚. 1.概念 Windows Azu ...
- Windows Azure Storage (19) 再谈Azure Block Blob和Page Blob
<Windows Azure Platform 系列文章目录> 请读者在参考本文之前,预习相关背景知识:Windows Azure Storage (1) Windows Azure St ...
- SqlServer2008安装时提示重启计算机失败 解决办法
问题描述: 在安装Sql Server 2008时提示重启计算机,重启之后不行,仍需要重启计算机. 如下图所示: 解决方法: 1.运行(或按键盘Win+R 组合键),输入regedit,调出注册表管理 ...
- windows命令——explorer
转至http://www.cnblogs.com/ymind/archive/2012/03/30/explorer-command-args.html 今天才知道,explorer原来可以这样用, ...
- Atitit 图像处理 深刻理解梯度原理计算.v1 qc8
Atitit 图像处理 深刻理解梯度原理计算.v1 qc8 1.1. 图像处理 梯度计算 基本梯度 内部梯度 外部梯度 方向梯度1 2. 图像梯度就是图像边缘吗?2 1.1. 图像处理 梯度计算 ...