1

I want to add the id i get from

$state.go('state1', {obj: {id: request.id, title: request.title}}

to the URL in

angular.module('app')  
  .config(function ($stateProvider) {
    $stateProvider
      .state('state1', {
        url : '/edit',
        params: {obj: null},
        ...
      }); 
  });

I accessed the id in my Controller using

vm.id = $stateParams.obj.id;

and tried adding it to the url by trying

url : '/edit/:id'
url : '/edit/:obj.id'

I tried searching for a while but it's either they are passing params (not object) or they are passing an object but uses a static url. I'm new to Angular can someone point out what i'm missing? Thanks.

1 Answer 1

1

The parameter in the url needs to match what you're passing in. Try this:

$stateProvider
      .state('state1', {
        url : '/edit/:id',
        params: {obj: null},
        ...
      }); 

Then call using:

$state.go('state1', {id: request.id, obj: {id: request.id, title: request.title}}
Sign up to request clarification or add additional context in comments.

2 Comments

I didn't know that was possible. Thank you very much for this! Works like a charm!!!
@ChesterLim You'll want to add a resolve function on the state to create the object if it doesn't exist. Otherwise you have an "URL" that really isn't an URL anymore and you can get into some confusion if you're not at the very least guarding against nulls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.