You could use an Angular Service to share variable acrosss multiple controllers.
angular.module('myApp', [])
.service('User', function () {
return {};
})
To share the data among independent controllers, Services can be used. Create a service with the data model that needs to be shared. Inject the service in the respective controllers.
function ControllerA($scope, User) {
$scope.user = User;
$scope.user.firstname = "Vinoth";
}
function ControllerB($scope, User) {
$scope.user = User;
$scope.user.lastname = "Babu";
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…