Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用$routeParam从服务加载数据_Javascript_Angularjs_Promise - Fatal编程技术网

Javascript 使用$routeParam从服务加载数据

Javascript 使用$routeParam从服务加载数据,javascript,angularjs,promise,Javascript,Angularjs,Promise,我正在尝试加载一组消息,这取决于作为应用程序路由一部分的ID。routeParams对象似乎是一个承诺,我不确定如何设置它,以便它等到routeParams对象加载后再加载消息组: var current = Messages.rest({m_gid:$routeParams.gid}).query({}, function () { $scope.messages.current = Messages.messages.current = current.data; }); 我确

我正在尝试加载一组消息,这取决于作为应用程序路由一部分的ID。routeParams对象似乎是一个承诺,我不确定如何设置它,以便它等到routeParams对象加载后再加载消息组:

var current = Messages.rest({m_gid:$routeParams.gid}).query({}, function () { 
    $scope.messages.current = Messages.messages.current = current.data;
}); 

我确信这很简单,我只是不知所措…

您可以订阅
$routeChangeSuccess

$rootScope.$on('$routeChangeSuccess', function(event, current, previous){
    //do work with $routeParams here
});