私は角度の付いたSPAを構築しています。コントローラーは2つあり、データを共有したいと考えています。 service/factoryを使用してデータを共有できません。ベローはコードです。コントローラー間でデータを共有できません
/*this service is a helper to submit multipart form data*/
appDls.service('multipartForm', ['$http', function($http){
this.post = function(url,data){
var responseVar = "";
var fd = new FormData;
for(var key in data){
fd.append(key,data[key]);
}
return $http.post(url,fd,{
transformRequest: angular.indentity,
headers: {'Content-Type':undefined}
});
}
}]);
/*this factory is for sharing data across controllers*/
appDls.factory('sharedFactory', function(){
var dataTobeShared = {};
var interface = {};
interface.add = function(d){dataTobeShared = d;}
interface.put = function(){return dataTobeShared;}
return interface;
});
/*this controller is for the main portal user redirection and portal rendering*/
appDls.controller('DlsappController', ['$scope', '$state','multipartForm','sharedFactory', function($scope,$state,multipartForm,sharedFactory){
$scope.login = function(){
var url = "../scripts/routes.php/authen";
multipartForm.post(url,$scope.login).then(function(d){
$scope.data = d.data;
});
$scope.data = sharedFactory.add;
$scope.data = {};
}
}]);
/*this controller is for landing page routing*/
appDls.controller('landingController', ['$scope', '$state','multipartForm','sharedFactory', function($scope,$state,multipartForm,sharedFactory){
$scope.fucking = sharedFactory.put;
}]);
、私は早く返事を探しています...私は上記のコードで間違っているものを教えてください。