繁体   English   中英

在路由时在不使用服务或Factory的情况下将JSON数据从控制器传递到另一个控制器

[英]Pass the JSON Data Between From Controller To another Controller with out using Services or Factory in angular JS while Routing

我在“ Dashboard页面中有“对象”,当从“仪表板”中单击“ Details页面”时,它应该重定向到“ Details页面,我想将JSON对象从“ Dashboard Controller传递到“ Details Controller ,有没有办法Angular JS Service或factory

myApp.controller('dashBoardController', ['$scope', function($scope) {

     $scope.detailsPage = function(Object){


     // I want this object available in details page controller

        $location.path('/detailsPage');
};

}]);

myApp.controller('detailsOageController', ['$scope', function($scope) {
  //  need Object data here
}]);

您可以通过以下方法实现从一个控制器到另一个控制器的数据共享。

  1. 使用服务/工厂(首选)
  2. 使用Rootscope和值将在全局范围内(不可取)
  3. 发射与广播

https://docs.angularjs.org/api/ng/type/ $ rootScope.Scope

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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