AngularJS工作原理--举例说明
2017-05-24 17:58
260 查看
在研究了angularjs接近半年的时间以后,终于差不多弄懂了angularjs的工作机制原理了:
拿一个例子说明一下吧:
HTML代码:
<ion-list>
<div style="margin-top: 44px;"></div>
<ion-item ng-repeat="item in items"
item="item"
ng-click="goToDetail(item)"
class="item-remove-animate" style="height: 65px;vertical-align: middle;padding-top: 1px;">
<div style="width: 100%;" class="warp">
<div style="font-size:16px;width: 100%;float:left;color: #000000;padding-top: 15px;">{{ item.OF_OFFICENAME }} <span style="color: #9b9b9b;">容纳{{ item.OF_MAXUSER }}人</span> <span style="color:#5077aa">已预订:{{}}次</span></div>
</div>
<!--</div>-->
</div>
</ion-item>
</ion-list>
conroller.js代码:
listFactory.getOffice(remindtime).then(function (response) {
console.log(response);
$scope.items = response;
});
service.js代码:
getOffice: function getList(date) {
var deferred = $q.defer();
var params = "{\"date\":\""+date+"\"}";
var url = '/serv?domain=getOffice¶ms=' + encodeURIComponent(params);
$http.post(url).success(function (response) {
deferred.resolve(response);
}).error(function (data) {
console.log("getList网络联接失败!");
$ionicPopup.alert({
title: '<b>错误!</b>',
template: '网络联接失败!'
})
deferred.reject();
});
return deferred.promise;
},
首先在service.js中定义一个方法叫
4000
getOffice,该方法是与后台数据库进行数据查询的接口,在前台页面能够显示出来数据的流程是首先在service里面写一个查询的方法,当页面需要显示容纳人数和预定次数时先调用对应的controller,然后会调用到 listFactory.getOffice,listFactory是controller
调用service方法的函数,点后面跟的是service里面定义的与数据库交互的方法名,response 则是后台数据库返回给前端的数据集合。最后你用一个循环把需要的数据遍历出来就大功告成啦~~~~~
拿一个例子说明一下吧:
HTML代码:
<ion-list>
<div style="margin-top: 44px;"></div>
<ion-item ng-repeat="item in items"
item="item"
ng-click="goToDetail(item)"
class="item-remove-animate" style="height: 65px;vertical-align: middle;padding-top: 1px;">
<div style="width: 100%;" class="warp">
<div style="font-size:16px;width: 100%;float:left;color: #000000;padding-top: 15px;">{{ item.OF_OFFICENAME }} <span style="color: #9b9b9b;">容纳{{ item.OF_MAXUSER }}人</span> <span style="color:#5077aa">已预订:{{}}次</span></div>
</div>
<!--</div>-->
</div>
</ion-item>
</ion-list>
conroller.js代码:
listFactory.getOffice(remindtime).then(function (response) {
console.log(response);
$scope.items = response;
});
service.js代码:
getOffice: function getList(date) {
var deferred = $q.defer();
var params = "{\"date\":\""+date+"\"}";
var url = '/serv?domain=getOffice¶ms=' + encodeURIComponent(params);
$http.post(url).success(function (response) {
deferred.resolve(response);
}).error(function (data) {
console.log("getList网络联接失败!");
$ionicPopup.alert({
title: '<b>错误!</b>',
template: '网络联接失败!'
})
deferred.reject();
});
return deferred.promise;
},
首先在service.js中定义一个方法叫
4000
getOffice,该方法是与后台数据库进行数据查询的接口,在前台页面能够显示出来数据的流程是首先在service里面写一个查询的方法,当页面需要显示容纳人数和预定次数时先调用对应的controller,然后会调用到 listFactory.getOffice,listFactory是controller
调用service方法的函数,点后面跟的是service里面定义的与数据库交互的方法名,response 则是后台数据库返回给前端的数据集合。最后你用一个循环把需要的数据遍历出来就大功告成啦~~~~~
相关文章推荐
- java栈stack和堆heap的工作原理,用途及区别?举例说明
- java栈stack和堆heap的工作原理,用途及区别?举例说明
- 互斥锁概念简单说明和举例
- 举例说明什么是隐马尔科夫模型(HMM)
- Python中list的详细操作描述(举例说明)
- 举例说明弱密码摄像头的简单破解方法,不涉及敏感信息,仅供防范!
- 举例说明如何创建和管理用户及组(添加删除用户,组成员的添加删除)
- 举例说明使用BufferedReader时出现乱码时的解决方法
- DNS的工作原理图解说明
- 举例说明数据库一、二、三及BCNF范式
- Android.mk和Application.mk文件语法规范说明及举例
- 关于是否添加索引就可以提高性能?能否举例说明
- UML类图符号 各种关系说明以及举例
- UML类图符号 各种关系说明以及举例(转载)
- 举例说明android中BroadcastReceiver的使用
- python yield用法举例说明
- ArrayList和LinkedList的区别是什么?举例说明LinkedList可实现的功能
- 举例说明了十大ES6功能
- java中HashMap有什么用,举例说明?
- 举例说明Python的CSV模块