简体   繁体   中英

how to pass object data from one controller to another controller in angularjs

实际上,我正在尝试在angularjs中填写表格,并且其数据已在其中一个控制器中接收到...我需要将相同的数据传递给另一个需要在另一个网页上显示的控制器

You should make use of angular service to do the same.

Create a service, that will hold model variables.

angular.service("dataService", function() {
    this.value1 = "";  
});

Then you can reference that service in your controllers,

angular.controller("myCntrl1", function($scope, dataService) {
    $scope.value1 = dataService.value1;
});


angular.controller("myCntrl2", function($scope, dataService) {
    $scope.value1 = dataService.value1;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM