coure2011 coure2011 - 1 year ago 114
AngularJS Question

how to pass query parameter in resolve method

Here is my js code

var MYApp = angular.module('myApp', ['ngRoute', 'myAppServices', 'ngSanitize'])

angular.module('myAppServices', ['ngResource'])
.factory('GridsAPI', function($resource) {
return {
GetUser: $resource('/MY/system/getUser/:id')
function ViewUserController($scope, user) {

function myRouter($routeProvider) {

.when('/users/view/:id', {
templateUrl: '/MY/system/users/view/:id',
controller: 'ViewUserController',
resolve: {
user: function(GridsAPI) {
//how to return user based on id passed to this url?

I want to get the user via ajax call before the view has loaded, how can I get the id parameter in resolve?

Answer Source

Inject $route and then:

resolve: {
    user: ['$route', 'GridsAPI', function($route, GridsAPI) {
      var userId = $;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download