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(表单) ...
随机推荐
- ORACLE导入导出工具的使用
ORACLE导出工具exp的使用: 1.将数据库TEST(远程的数据库必须为连接标志符)完全导出,用户名system,密码manager,导出到D:\daochu.dmp中: exp s ...
- bzoj1078
题解: 一道思路题(话说在那个时候有多少人知道左偏树) 考虑最后一个加进来的点 必然满足 (1)从它到根一直是左链上去的 (2)没有左右子树 在这些点中寻找一个最浅的 然后删除 代码: #includ ...
- Jenkins插件开发(一)--环境搭建
最近写了一个jenkins插件,功能比较简单,时间主要是花在对jenkins插件框架和Maven的熟悉上.jenkins插件虽然以前也接触过一点,不过现在都忘得差不多了,这个笔记权当知识点记录,顺带介 ...
- WIN8.1 PRO RTM VOL.2013.09.18
文件名:cn_windows_8_1_pro_vl_x64_dvd_2791218.isoSHA1:61C002551763E22B64EB1BACEFFE83620114C3D6 文件名:cn_wi ...
- 2018.11.23 Cypress BLE module test
CYx63BPA BLE module IQC test guide Test Jig setting:1. Connect USB1 and USB2 with computer serial ...
- C# 调用C++ DLL 的类型转换(转载版)
最近在做视频监控相关的demo开发,实现语言是C#,但视频监控的SDK是C++开发的,所以涉及到C#调用C++的dll库.很多结构体.参数在使用时都要先进行转换,由非托管类型转换成托管类型后才能使用. ...
- iOS-----多线程之NSThread
多线程 iOS平台提供了非常优秀的多线程支持,程序可以通过非常简单的方式来启动多线程,iOS平台不仅提供了NSThread类来创建多线程,还提供了GCD方式来简化多线程编程,提供了NSOperatio ...
- Oozie_04总结一下workflowf的运行流程【20161116】
4.1 bin/oozie ..... 提交任务 [hadoop@hadoop01 oozie-4.0.0-cdh5.3.6]$ bin/oozie job -oozie http://hadoop0 ...
- flow 编写flow-typed 定义(官方文档)
此为官方文档,因为墙的问题,记录下来: Before spending the time to write your own libdef, we recommend that you look to ...
- 树莓派系列教程:安装系统与配置环境,使用PuTTy与VNC图形界面远程登录
本文所需物品清单: Raspberry Pi 3 Model B 主板.SD卡与读卡器(用于烧录系统) 资料整理来源在文尾 需要下载的资源与工具: 推荐系统-Raspbian 树莓派官方深度定制的硬件 ...