1.引入脚本文件

<link rel="stylesheet" href="http://lib.sinaapp.com/js/bootstrap/v3.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" />
<script src="http://lib.sinaapp.com/js/jquery/2.0.1/jquery-2.0.1.min.js"></script>
<script src="http://lib.sinaapp.com/js/bootstrap/v3.0.0/js/bootstrap.min.js"></script>
<script src="http://lib.sinaapp.com/js/angular.js/angular-1.2.19/angular.min.js"></script>
<script src="http://lib.sinaapp.com/js/angular.js/angular-1.2.19/angular-route.min.js"></script>

2.显示值

<body>
<div ng-app="app" ng-controller="controller">
<h1>{{ inputValue }}</h1>
</div>
</body>
<script type="text/javascript">
var app=angular.module('app',[]);
app.controller('controller',function($scope){
$scope.inputValue="william's home";
});
</script>

3.双向绑定

<div  ng-app="app" ng-controller="controller">
<input type="text" ng-model="inputValue">
<h1>{{ inputValue }}</h1>
</div>

修改input中的值,h1标题中的内容也会修改

4添加事件

<body>
<div ng-app="app" ng-controller="controller">
<button ng-click="myclick()">Click Me</button>
</div>
</body>
<script type="text/javascript">
var app=angular.module('app',[]);
app.controller('controller',function($scope){
$scope.myclick=function(){
alert("click")
}
});
</script>

可以看出对$scope扩展属性和方法,就可以在html通过ng-model,ng-click使用

5 显示表格

<body>
<div ng-app="app" ng-controller="controller">
<table class="">
<tr ng-repeat="x in names">
<td>{{ x.firstName }}</td>
<td>{{ x.lastName }}</td>
</tr>
</table>
</div>
</body>
<script type="text/javascript">
var app=angular.module('app',[]);
app.controller('controller',function($scope){
$scope.names=[
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
});
</script>

6通过get获取数据

<body>
<div ng-app="app" ng-controller="controller">
<table class="">
<tr ng-repeat="x in names">
<td>{{ x.firstName }}</td>
<td>{{ x.lastName }}</td>
</tr>
</table>
</div>
</body>
<script type="text/javascript">
var app=angular.module('app',[]);
app.controller('controller',function($scope,$http){
$http.get("data.json")
.success(function (response) {$scope.names = response;});
});
</script>

data.json

[
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]

get后的url可以替换为任意地址,比如服务端的rest api地址,只要返回类型是json即可

angularJS快速入门的更多相关文章

  1. AngularJS快速入门指南20:快速参考

    thead>tr>th, table.reference>tbody>tr>th, table.reference>tfoot>tr>th, table ...

  2. AngularJS快速入门指南19:示例代码

    本文给出的大部分示例都可以直接运行,通过点击运行按钮来查看结果,同时支持在线编辑代码. <div ng-app=""> <p>Name: <input ...

  3. AngularJS快速入门指南18:Application

    是时候创建一个真正的AngularJS单页面应用程序了(SPA). 一个AngularJS应用程序示例 你已经了解了足够多的内容来创建第一个AngularJS应用程序: My Note Save Cl ...

  4. AngularJS快速入门指南17:Includes

    使用AngularJS,你可以在HTML中包含其它的HTML文件. 在HTML中包含其它HTML文件? 当前的HTML文档还不支持该功能.不过W3C建议在后续的HTML版本中增加HTML import ...

  5. AngularJS快速入门指南16:Bootstrap

    thead>tr>th, table.reference>tbody>tr>th, table.reference>tfoot>tr>th, table ...

  6. AngularJS快速入门指南15:API

    thead>tr>th, table.reference>tbody>tr>th, table.reference>tfoot>tr>th, table ...

  7. AngularJS快速入门指南14:数据验证

    thead>tr>th, table.reference>tbody>tr>th, table.reference>tfoot>tr>th, table ...

  8. AngularJS快速入门指南13:表单

    一个AngularJS表单是一组输入型控件的集合. HTML控件 HTML输入型标签标包括: input标签 select标签 button标签 textarea标签 HTML表单 HTML表单将各种 ...

  9. AngularJS快速入门指南12:模块

    AngularJS模块定义了一个application. 模块是一个application中不同部分的容器. application中的所有控制器都应该属于一个模块. 带有一个控制器的模块 下面这个a ...

  10. AngularJS快速入门指南11:事件

    AngularJS拥有自己的HTML事件指令. ng-click指令 ng-click指令定义了AngularJS的click事件. <div ng-app="" ng-co ...

随机推荐

  1. Android 子线程请求ASP.NET后台

    首先定义布局文件,及点击事件 public class MainActivity extends Activity { private final int MSG_HELLO = 0; private ...

  2. HDOJ 2071 Max Num

    Problem Description There are some students in a class, Can you help teacher find the highest studen ...

  3. 接口中的成员变量必须是static

    首先要弄清接口的含义. 接口就是提供一种统一的'协议’, 而接口中的属性也属于'协议’中的成员.它们是公共的,静态的,最终的常量.相当于全局常量. 在interface里面的变量都是public st ...

  4. 九度online judge 1543 二叉树

    题目1543:无限完全二叉树的层次遍历 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:389 解决:54 题目描述: 有一棵无限完全二叉树,他的根节点是1/1,且任意一个节点p/q的左儿 ...

  5. PHP面试题(二)

    前言 从网上找了一套号称是百度的php面试题目,这里记录一下 PHP的gc机制 php的垃圾回收机制注意以下几点即可: 引用计数refcount和is_ref,也就是php不会随意的malloc内存空 ...

  6. Cstyle的UEFI导读之SEC第一篇 Reset Vector

        最近小看了一下SEC部分的code,现在来做个总结.所谓SEC就是CPU刚刚完成硬件初始化的是时候执行的和CPU体系架构息息相关的代码.主要是为后续CPU以及Chipset初始化代码所需的必备 ...

  7. crossfire 346# B

    Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya ...

  8. Visual Studio的2个有趣的插件:声音控制和放屁:)

    .NET Slave | Talk to, hear, touch and see your code介绍了2个有趣的Visual Studio的插件,你可以通过它们和你的代码对话. 声音控制(Voi ...

  9. Android代码混淆

    混淆器(ProGuard) --- 混淆器通过删除从未用过的代码和使用晦涩名字重命名类.字段和方法,对代码进行压缩,优化和混淆.结果是一个比較小的.apk文件,该文件比較难进行逆向project.因此 ...

  10. PHP 函数的“引用返回”概念释疑(转)

    很多时候我们会看到这样的代码(出自 CI 框架源码): 1 $class =& load_class('a','b'); 我们都知道其中的'&'是指引用,但是它的作用是什么呢?它能够解 ...