如何在AngularJS另一个控制器使用变量从控制器 [英] How to use variables from a controller in another controller in AngularJS
本文介绍了如何在AngularJS另一个控制器使用变量从控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在AngularJS新的,我想使用用户名
和密码
变数,我在此得到控制器:
I'm new in AngularJS and I want to use the username
and password
variables that I get in this controller:
.controller('LoginCtrl', function($scope, LoginService, $ionicPopup, $state, Api) {
$scope.data = {};
$scope.login = function() {
LoginService.loginUser($scope.data.username, $scope.data.password)
.success(function(data) {
$scope.data = {}
$state.go('tabs.extranet');
})
.error(function(data) {
var alertPopup = $ionicPopup.alert({
title: 'Acceso denegado',
template: 'Por favor, compruebe su usuario y/o contraseña'
});
$state.go('tabs.extranet');
});
};
})
在此控制器
.controller('SaesoTabCtrl', function($scope, $sce, Saeso, Api){
//some code....
}
感谢
推荐答案
尽量把的 $ rootScope
。它是从应用程序的任何地方访问。
Try to put your data inside the $rootScope
. It is accessible from anywhere in the application.
这篇关于如何在AngularJS另一个控制器使用变量从控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文