AngularJS-data sharing between multiple controllers and angularjs Controllers
To share data between controllers, you need to add a method in the service to store the user name. Remember, the service in
The life cycle of an application is in singleton mode. Therefore, the user name can be securely stored in the instance.
<! DOCTYPE html>
| 12345678910111213141516171819 |
var myApp = angular.module('myApp', []); myApp.factory('Data', function(){ return {message:'Small pinggo'}; }); myApp.controller('firstController', function($scope,Data){ $scope.person = { name: "Xiao guoping" }; $scope.Data = Data;}); myApp.controller('secondController', function($scope,Data){ $scope.person = $scope.$$prevSibling.person;// The basic type cannot be changed. Only objects can be referenced. $scope.Data = Data;}); |
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.