SoFunction
Updated on 2025-04-13

Detailed explanation of AngularJS controller calling factory

1. Definition File

var appFactorys = ('', []) 
('HouseFactory', function () { 
  var houseList = [ 
    { id: 0, title: 'Emergency sales of the North Second Ring Road, the community is fully equipped and finely decorated', price: '88.0', describe: '2 bedroom 1 living room 120 square meters', img: 'img/' }, 
    { id: 1, title: 'Emergency sales East Second Ring Road, the community is fully equipped and well-decorated', price: '88.0', describe: '2 bedroom 1 living room 120 square meters', img: 'img/' }, 
    { id: 2, title: 'Emergency sale of the South Second Ring Road, the community is fully equipped and well-decorated', price: '87.0', describe: '2 bedroom 1 living room 120 square meters', img: 'img/' }, 
    { id: 3, title: 'Emergency sales West Second Ring Road, the community is fully equipped and well-decorated', price: '86.0', describe: '2 bedroom 1 living room 120 square meters', img: 'img/' }, 
    { id: 4, title: 'Emergency sales of the North Second Ring Road, the community is fully equipped and finely decorated', price: '85.0', describe: '2 bedroom 1 living room 120 square meters', img: 'img/' } 
  ]; 
  return { 
      all: function () { 
        return houseList; 
      }, 
    }; 
}); 

2. Reference file in file

Copy the codeThe code is as follows:

('starter', ['ionic', 'ngCordova', '','','', '']) 

3. Call factory in controller

('HouseCtrl', function ($scope, $timeout, $ionicModal, $ionicActionSheet, $http, $cordovaToast, $ionicLoading, HouseFactory) { 
  // $ = [ 
  // { id: 0, title: 'Emergency sale North Second Ring Road, the community is fully equipped with fine decoration', price: '88.0', describe: '2 bedrooms and 1 living room 120 square meters', img: 'img/' },  // { id: 1, title: 'Emergency sale East Second Ring Road, the community is fully equipped with fine decoration', price: '88.0', describe: '2 bedrooms and 1 living room 120 square meters', img: 'img/' },  // { id: 2, title: 'Emergency Sales South Second Ring Road Community is fully equipped with fine decoration', price: '87.0', describe: '2 bedrooms and 1 living room 120 square meters', img: 'img/' },  // { id: 3, title: 'Emergency Sales West Second Ring Road Community is fully equipped with fine decoration', price: '86.0', describe: '2 bedrooms and 1 living room 120 square meters', img: 'img/' },  // { id: 4, title: 'Emergency sale North Second Ring Road, the community is fully equipped with fine decoration', price: '85.0', describe: '2 bedrooms and 1 living room 120 square meters', img: 'img/' }  // ]; 
 
  /* Call data */ 
  $ = (); 
 
}) 

4. HTML page call

<ion-list> 
  <ion-item class="item item-thumbnail-left" ng-repeat="item in houseList" href="#/housedetail/{{}}" rel="external nofollow" style="padding--bottom:2px"> 
    <img ng-src="{{}}"> 
    <h2>{{}}</h2> 
    <dd class="assertive cus-price">{{}}Ten thousand yuan</dd> 
    <dd class="u-f-h4">{{}}</dd> 
  </ion-item> 
</ion-list> 

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.