AngularJS学习笔记(1)——MVC模式的清单列表效果
MVC模式的清单列表效果
使用WebStorm新建todo.html并链入bootstrap.css、bootstrap-theme.css、angular.js。要链入的相关css和js文件预先准备好,文件目录如下:
使用MVC模式前的代码:
<!DOCTYPE html>
<html ng-app>
<head>
<meta charset="UTF-8">
<title>TO DO List</title>
<link href="./bootstrap/css/bootstrap.css" rel="stylesheet"/>
<link href="./bootstrap/css/bootstrap-theme.css" rel="stylesheet"/>
</head>
<body>
<div class="page-header">
<h1>Yimi's TO DO List</h1>
</div>
<div class="panel">
<div class="input-group">
<input class="form-control"/>
<span class="input-group-btn">
<button class="btn btn-default">Add</button>
</span>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th>Done</th>
</tr>
</thead>
<tbody>
<tr><td>练车</td><td>Yes</td></tr>
<tr><td>看课外书</td><td>No</td></tr>
</tbody>
</table>
</div>
</body>
</html>
使用MVC模式后代码如下:
<!DOCTYPE html>
<html ng-app="todoApp">
<head>
<meta charset="UTF-8">
<title>TO DO List</title>
<link href="./bootstrap/css/bootstrap.css" rel="stylesheet"/>
<link href="./bootstrap/css/bootstrap-theme.css" rel="stylesheet"/>
<script src="./angularJs/angular.js"></script>
<script>
var model = {
user:"Yimi",
items:[{action:"练车",done:true},
{action:"看课外书",done:false}]
};
var todoApp = angular.module("todoApp",[]);
todoApp.controller("ToDoCtrl",function($scope){ //以$开头的变量名表示AngularJS的内置特性
$scope.todo = model;
});
</script>
</head>
<body ng-controller="ToDoCtrl">
<div class="page-header">
<h1>{{todo.user}}'s TO DO List</h1>
<span class="label label-default">{{todo.items.length}}</span>
</div>
<div class="panel">
<div class="input-group">
<input class="form-control"/>
<span class="input-group-btn">
<button class="btn btn-default">Add</button>
</span>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th>Done</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in todo.items">
<td>{{item.action}}</td>
<td>{{item.done}}</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
效果图如下:
使用Chrome浏览器查看
模型-视图-控制器(MVC)
M:模型。程序中的数据
......
var model = {
user:"Yimi",
items:[{action:"练车",done:true},
{action:"看课外书",done:false}]
};
......
V:视图。显示数据的逻辑
比如在间通过{{和}}调用之前定义的模型的值
......
<h1>{{todo.user}}'s TO DO List</h1>
<span class="label label-default">{{todo.items.length}}</span>
......
<tr ng-repeat="item in todo.items">
<td>{{item.action}}</td>
<td>{{item.done}}</td>
</tr>
......
C:控制器。对数据进行操作的逻辑
var todoApp = angular.module("todoApp",[]);
todoApp.controller("ToDoCtrl",function($scope){ //以$开头的变量名表示AngularJS的内置特性
$scope.todo = model;
});
<body ng-controller="ToDoCtrl">
AngularJS学习笔记(1)——MVC模式的清单列表效果的更多相关文章
- AngularJS学习笔记(2)——与用户交互的动态清单列表
与用户交互的动态清单列表 以我之前写的一个清单列表页面作为例子(MVC模式的清单列表效果),优化前代码如下: <!DOCTYPE html> <html ng-app="t ...
- jsp学习笔记:mvc开发模式
jsp学习笔记:mvc开发模式2017-10-12 22:17:33 model(javabe)与view层交互 view(视图层,html.jsp) controller(控制层,处理用户提交的信息 ...
- AngularJs学习笔记--expression
原版地址:http://code.angularjs.org/1.0.2/docs/guide/expression 表达式(Expressions)是类Javascript的代码片段,通常放置在绑定 ...
- AngularJs学习笔记--Using $location
原版地址:http://code.angularjs.org/1.0.2/docs/guide/dev_guide.services.$location 一.What does it do? $loc ...
- AngularJs学习笔记--Understanding the Model Component
原版地址:http://docs.angularjs.org/guide/dev_guide.mvc.understanding_model 在angular文档讨论的上下文中,术语“model”可以 ...
- AngularJs学习笔记--Understanding the Controller Component
原版地址:http://docs.angularjs.org/guide/dev_guide.mvc.understanding_model 在angular中,controller是一个javasc ...
- AngularJs学习笔记--Understanding Angular Templates
原版地址:http://docs.angularjs.org/guide/dev_guide.mvc.understanding_model angular template是一个声明规范,与mode ...
- AngularJS 学习笔记--01
学习 AngularJS 要先了解 MVC 模式 , 即 " 模型--视图--控制器 " . 模型: 包含了需要用到的数据 ; 有两种广义上的模型 : 视图模型 , 只表示从控制器 ...
- AngularJs学习笔记--Forms
原版地址:http://code.angularjs.org/1.0.2/docs/guide/forms 控件(input.select.textarea)是用户输入数据的一种方式.Form(表单) ...
随机推荐
- php---------取汉字的第一个字的首字母
开发中用到的方法,取出第一个汉字的首字母: /** * 取汉字的第一个字的首字母 * @param string $str * @return string|null */ function getF ...
- bzoj-5049-线段树
5039: [Jsoi2014]序列维护 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 323 Solved: 193[Submit][Status ...
- OleDbCommand使用参数应该注意的地方
最近写程序用到OleDbCommand的Parameter写数据库,遇到很多问题: 1.OLE DB .NET Framework 数据提供程序和 ODBC .NET Framework 数据提供程序 ...
- iOS-程序启动原理和UIApplication
iOS开发UI篇—程序启动原理和UIApplication 一.UIApplication 1.简单介绍 (1)UIApplication对象是应用程序的象征,一个UIApplication对象就 ...
- 卸载oracle11g步骤图解
卸载oracle11g步骤图解 重启电脑即可
- IE8下的typeof(console.log)为"object"的BUG
今天发现IE8在开启过控制台后,console.log虽然可用,也是确实是一个函数,但是对其执行typeof操作返回的确是"object" 原生IE8:
- New Concept English Two 4
听力口语是一起的,其中,受中国英语发音的影响,我们的听力识别度会很差,歪果仁发的地道英语,极有可能我们听不懂.这涉及到:自然拼读法的训练,还有纠音练习.当然,听简单的美剧的音频,然后练习是最好的. 新 ...
- 深入php redis pconnect
深入php redis pconnect pconnect是phpredis中用于client连接server的api. API文档中的一句原文: The connection will not be ...
- 在Android中来修改SQL里面的权限和显示内容
1.在Android中建立了一个数据库. 然后要知道存储数据库的路劲.得到路劲然后进入cmd里面进到 手机终端. 2.利用splite3来显示数据库里面的东西. 3.利用chmod来修改数据库文件的权 ...
- 《DSP using MATLAB》Problem 2.2
1.代码: %% ------------------------------------------------------------------------ %% Output Info abo ...