AngularJS学习笔记(1)——MVC模式的清单列表效果
2017-07-14 21:37
330 查看
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学习笔记(2)——与用户交互的动态清单列表
- 淘宝购物车展示效果列表清单
- 论坛源码推荐(4月28日):列表项目的波浪效果 兼容iOS 6与iOS 7的自定义导航条
- Unity 滑动列表时实现平滑阻尼效果修改篇
- dede文章列表加上序号效果
- iphone实现类似Android Grid效果的列表视图
- JQuery实现页面企业广告图片切换和新闻列表滚动效果
- 拉勾网企业图片列表效果
- [安卓] 16、ListView和GridView结合显示单元实现自定义列表显示效果
- jquery用div实现下拉列表的效果
- android 仿qq好友列表分组效果及联系人分组效果
- html怎样实现数据列表的下拉效果
- Android开发学习之仿手机QQ消息列表侧滑删除效果
- dede 如何调用其他栏目的文章或者缩略图列表且有分页效果?
- 下拉列表提示效果
- 基于Qt的类似QQ好友列表抽屉效果的实现
- 如何去掉ListView/GridView等列表控件滑到顶部或底部时的模糊边缘效果
- 垂直列表导航菜单效果
- [转载] 模仿淘宝列表页面的工具栏随屏幕滚动效果
- vue 过渡效果-列表过渡