希望,我的問題本身傳達了我所期待的。 請詳細說明文字 1.創建模塊。無法獲取多個控制器中模型的內容AngularJS
var ang = angular.module('myApp',[]);
- 我有一個名爲controller1的控制器,幷包含'campaign'工廠。
//controllerone.js
ang.controller('controller1', function(campaign){ $scope.campaigns = new campaign(); //Here the whole campaign object is displayed with data, refer the Image 1 attached console.log($scope.campaigns); });
ang.factory('campaign', function($http){
var campaign = function(){
this.timePeriodList = buildTimePeriodList();
...
...
this.campaignList = [];
};
Campaigns.prototype.fetchCampaigns = function() {
//Some service call to load the data in this.campaignList
};
});
現在試圖調用同一個廣告活動廠第二控制器,只得到對象結構,沒有得到數據。
//controlertwo.js
ang.controller('controller2', function(campaign){ $scope.campaigns = new campaign(); //Here only the campaign object structure is displayed, but no data for campaignList, ref image 2 attached console.log($scope.campaigns); });
以來,工廠服務是一個單獨的對象,我期待了同樣的結果,因爲我在controllerone.js了,
圖片1:
圖片2:
如果你想要利用單身人士,請停止使用'new'。 – allenhwkim 2014-10-01 16:58:10