ANGULARJS Controller Call Factory

Source: Internet
Author: User


1. Define Factory.js files





var appFactorys = angular.module('starter.factorys', [])
appFactorys.factory('HouseFactory', function () {
var houseList = [
{ID: 0, Title: 'sale of complete and fine decoration of Beierhuan district', price: '88.0', Description: '120 square meters of room 1, room 2', IMG: 'img / Ben. PNG'},
{ID: 1, Title: 'urgent sale of complete and fine decoration of East 2nd Ring Road community', price: '88.0', Description: '120 square meters of room 1, room 2', IMG: 'img / max.png'},
{ID: 2, Title: 'the south 2nd Ring Road community is fully equipped with fine decoration', price: '87.0', Description: 'room 1, room 2, 120 square meters', IMG:' img / Adam. JPG '},
{ID: 3, Title: 'urgent sale of complete and fine decoration of West 2nd Ring Road community', price: '86.0', Description: '120 square meters of room 1, room 2', IMG: 'img / Perry. PNG'},
{ID: 4, Title: 'sale of complete and fine decoration of Beierhuan district', price: '85.0', Description: '120 square meters of room 1, room 2', IMG: 'img / Mike. PNG'}
];
Return {
all: function () {
return houseList;
}
}
};





2. Referencing factory.js file in App.js file



Angular.module (' starter ', [' Ionic ', ' Ngcordova ', ' starter.directives ', ' Starter.factorys ', ' starter.services ', '] Starter.customcontrollers '])

 





3. Call factory in controller





Appcontrollers.controller (' Housectrl ', function ($scope, $timeout, $ionicModal, $ionicActionSheet, $http, $ Cordovatoast, $ionicLoading, housefactory) {
    //$scope. houselist = [/
    /     {id:0, title: ' Urgent sale of the North two-ring community supporting complete fine decoration ', PR Ice: ' 88.0 ', describe: ' 2 Room 1 Hall 120 square meters ', img: ' Img/ben.png '},
    //     {id:1, title: ' Urgent sale East two ring community supporting complete fine decoration ', Price: ' 88.0 ', D  Escribe: ' 2 Room 1 Hall 120 square meters ', img: ' Img/max.png '},
    //     {id:2, title: ' Urgent sales South two ring community complete finishing ', Price: ' 87.0 ', describe: ' 2 Room 1 Hall  120 square meters ', img: ' img/adam.jpg '},
    //     {id:3, title: ' Urgent sale West two ring plot complete complete fine decoration ', Price: ' 86.0 ', describe: ' 2 Room 1 Hall 120 square meters ', IMG: ' Img/perry.png '},
    //     {id:4, title: ' Urgent sale of the North two-ring community complete matching fine decoration ', Price: ' 85.0 ', describe: ' 2 Room 1 Hall 120 square meters ', img: ' Img/mike. PNG '}
    //];

    /* Call Factory.js data
    /$scope. Houselist = Housefactory.all ();

})





4, HTML page calls





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







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.