My question is clear and straightforward. Let me explain in detail: 1. I have created a module.
var ang = angular.module('myApp', []);
- I have a controller named controller1, which includes the 'campaign' factory.
//controllerone.js
ang.controller('controller1', function(campaign){ $scope.campaigns = new campaign(); //The entire campaign object with data is displayed here, please refer to Image 1 attached console.log($scope.campaigns); });
ang.factory('campaign', function($http){
var campaign = function(){
this.timePeriodList = buildTimePeriodList();
...
...
this.campaignList = [];
};
Campaigns.prototype.fetchCampaigns = function() {
//Service call to populate the data in this.campaignList
};
});
Now when trying to use the same campaign factory in the second controller, only the object structure is retrieved without any data.
//controlertwo.js
ang.controller('controller2', function(campaign){ $scope.campaigns = new campaign(); //Only the structure of the campaign object is shown, but no data for campaignList, see image 2 attached console.log($scope.campaigns); });
Since the factory service is a singleton object, I expected the same result as in controllerone.js,
Image 1:
Image 2: