我正在建造一個有角度和纖細框架的spa。根據下面提到的代碼,我試圖做的是,成功提交用戶/ psw時,登錄頁面控制器會將數據傳遞到登錄頁面控制器。當我將工廠放置在http調用/登錄功能之外時,它獲取數據,但着陸頁工廠不提供數據。當我把它放進去時,它就停下來工作。請幫我....工廠無法將數據傳送到另一個控制器
這家工廠是在控制器之間的數據共享
appDls.factory('sharedFactory', function() {
var dataTobeShared = {};
var interface = {};
interface.add = function (d) {
dataTobeShared = d;
}
interface.put = function() {
return dataTobeShared;
}
return interface;
});
該控制器是主要門戶用戶重定向和門戶渲染
appDls.controller('DlsappController', ['$scope', '$state', 'multipartForm', 'sharedFactory', '$window', function ($scope, $state, multipartForm, sharedFactory, $window) {
$scope.Userdata = [];
$scope.login = function() {
var url = "../scripts/routes.php/authen";
multipartForm.post(url, $scope.login).then(function (d) {
$scope.Userdata.push(d.data[0]);
sharedFactory.add($scope.Userdata);
$window.location.href = '../portal/landing.php';
});
}
}]);
此控制器用於登陸頁面路由
appDls.controller('landingController', ['$scope', '$state', 'multipartForm', 'sharedFactory', function ($scope, $state, multipartForm, sharedFactory) {
$scope.UserInfo = sharedFactory.put();
$scope.$watch('UserInfo', function (newValue, oldValue) {
/*here we can use the user data from login page*/
if (newValue.length == 1) {
alert(newValue[0].fullname);
$state.go(newValue[0].proftype);
} else {
alert("user not logged in successfully!");
$state.go('default');
}
}, true);
}]);
請編輯您的帖子停止呼喊 - 使用所有帽子這是非常粗魯無處不在。 –
感謝您的評論...我編輯過的問題.... –