詳解AngularJS controller調(diào)用factory
更新時間:2017年05月19日 11:16:54 作者:KingCruel
本篇文章主要介紹了詳解AngularJS controller調(diào)用factory,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
1、定義 factory.js 文件
var appFactorys = angular.module('starter.factorys', [])
appFactorys.factory('HouseFactory', function () {
var houseList = [
{ id: 0, title: '急售北二環(huán) 小區(qū)配套齊全 精裝修', price: '88.0', describe: '2室1廳 120平米', img: 'img/ben.png' },
{ id: 1, title: '急售東二環(huán) 小區(qū)配套齊全 精裝修', price: '88.0', describe: '2室1廳 120平米', img: 'img/max.png' },
{ id: 2, title: '急售南二環(huán) 小區(qū)配套齊全 精裝修', price: '87.0', describe: '2室1廳 120平米', img: 'img/adam.jpg' },
{ id: 3, title: '急售西二環(huán) 小區(qū)配套齊全 精裝修', price: '86.0', describe: '2室1廳 120平米', img: 'img/perry.png' },
{ id: 4, title: '急售北二環(huán) 小區(qū)配套齊全 精裝修', price: '85.0', describe: '2室1廳 120平米', img: 'img/mike.png' }
];
return {
all: function () {
return houseList;
},
};
});
2、在 app.js 文件引用 factory.js 文件
復(fù)制代碼 代碼如下:
angular.module('starter', ['ionic', 'ngCordova', 'starter.directives','starter.factorys','starter.services', 'starter.customControllers'])
3、在controller中調(diào)用factory
appControllers.controller('HouseCtrl', function ($scope, $timeout, $ionicModal, $ionicActionSheet, $http, $cordovaToast, $ionicLoading, HouseFactory) {
// $scope.houseList = [
// { id: 0, title: '急售北二環(huán) 小區(qū)配套齊全 精裝修', price: '88.0', describe: '2室1廳 120平米', img: 'img/ben.png' },
// { id: 1, title: '急售東二環(huán) 小區(qū)配套齊全 精裝修', price: '88.0', describe: '2室1廳 120平米', img: 'img/max.png' },
// { id: 2, title: '急售南二環(huán) 小區(qū)配套齊全 精裝修', price: '87.0', describe: '2室1廳 120平米', img: 'img/adam.jpg' },
// { id: 3, title: '急售西二環(huán) 小區(qū)配套齊全 精裝修', price: '86.0', describe: '2室1廳 120平米', img: 'img/perry.png' },
// { id: 4, title: '急售北二環(huán) 小區(qū)配套齊全 精裝修', price: '85.0', describe: '2室1廳 120平米', img: 'img/mike.png' }
// ];
/* 調(diào)用Factory.js數(shù)據(jù) */
$scope.houseList = HouseFactory.all();
})
4、html頁面調(diào)用
<ion-list>
<ion-item class="item item-thumbnail-left" ng-repeat="item in houseList" href="#/housedetail/{{item.id}}" rel="external nofollow" style="padding--bottom:2px">
<img ng-src="{{item.img}}">
<h2>{{item.title}}</h2>
<dd class="assertive cus-price">{{item.price}}萬元</dd>
<dd class="u-f-h4">{{item.describe}}</dd>
</ion-item>
</ion-list>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- AngularJS之自定義服務(wù)詳解(factory、service、provider)
- AngularJS自定義服務(wù)與fliter的混合使用
- Angularjs 自定義服務(wù)的三種方式(推薦)
- AngularJs自定義服務(wù)之實現(xiàn)簽名和加密
- angularjs封裝$http為factory的方法
- angularJS Provider、factory、service詳解及實例代碼
- 簡介AngularJS中使用factory和service的方法
- angularjs自定義ng-model標簽的屬性
- 詳解AngularJS中自定義過濾器
- AngularJS創(chuàng)建自定義指令的方法詳解
- AngularJS基于factory創(chuàng)建自定義服務(wù)的方法詳解
相關(guān)文章
Angular 2應(yīng)用的8個主要構(gòu)造塊有哪些
這篇文章主要為大家詳細介紹了Angular 2應(yīng)用的8個主要構(gòu)造塊,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-10-10
AngularJS頁面帶參跳轉(zhuǎn)及參數(shù)解析操作示例
這篇文章主要介紹了AngularJS頁面帶參跳轉(zhuǎn)及參數(shù)解析操作,結(jié)合具體實例形式分析了AngularJS使用URL傳遞參數(shù)及參數(shù)的接收、解析等相關(guān)操作技巧,需要的朋友可以參考下2017-06-06
Angular外部使用js調(diào)用Angular控制器中的函數(shù)方法或變量用法示例
這篇文章主要介紹了Angular外部使用js調(diào)用Angular控制器中的函數(shù)方法或變量用法,結(jié)合實例形式分析了Angular基于外部JS調(diào)用控制器中方法與變量的具體實現(xiàn)步驟與相關(guān)技巧,需要的朋友可以參考下2016-08-08
AngularJs Understanding the Controller Component
本文主要介紹AngularJs Understanding the Controller Component的內(nèi)容,這里整理了相關(guān)資料,及簡單示例代碼,有興趣的小伙伴可以參考下2016-09-09
spring+angular實現(xiàn)導(dǎo)出excel的實現(xiàn)代碼
這篇文章主要介紹了spring+angular實現(xiàn)導(dǎo)出excel的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-02-02

