2016-03-28 149 views
0

我有一个页面,其中有一个下拉菜单,我的目标是当我从下拉菜单中选择任何值并单击Next时,它将使用ngRouteProvider切换到下一页, $ http.post,我需要传递数据作为回报负载。路由时将值从一个页面传递到另一个页面

    .when('/xyz/step2', { 
        templateUrl: partial('replacStep2.html'), 
        controller: 'xyzCtrl', 
        resolve: { 
         cardTypeDetails: ['$http', function ($http) { 
          return  $http.post(appContext('xyz.json'),{}); 

         }] 
        } 

       }) 

回答

0

您可以创建一个工厂并在其中设置一个变量,稍后可以将该工厂注入到您的解析块中并通过它访问您的变量。

resolve: { 
    cardTypeDetails: ['$http','sharedFactory', function ($http,sharedFactory) { 
    console.log(sharedFactory.sharedVariable); //use it like this 
    return $http.post(appContext('xyz.json'),{}); 

    }] 
} 

和工厂

angular.module('demoApp').factory('sharedFactory',function(){ 
    return { 
     sharedVariable:null 
    }; 
}); 

还是以同样的方式,你可以使用$rootScope传递变量(如果你对大没有做,但不是伟大的性能的变量。)

Passing variables from one controller to another with $rootscope

+0

如何在解析模块中注入工厂或注入$ rootscope的任何示例也有帮助。 – user3045179

+0

就像你注入'$ http'服务一样。我相应地更新我的答案。 –

+0

如何在进行JSON调用时传递数据。当我试图传递数据时,它显示,未经授权的错误。返回$ http.post(appContext('xyz.json'),{name:'Ankit'}); – user3045179

相关问题