1

I am trying to get UI router to have a detailed message view, here is the code:

  .state('app.messages.detail', {
        url: 'messages/{id}',
        templateUrl: 'templates/views/message.html',
        controller: function($scope, sharedProperties, $stateParams) {
          console.log($stateParams);
          messages = sharedProperties.getMessages();
          $scope.message = messsages.name[$stateParams.id];
    }
  })

Here is the messages array:

var messages = { 
  "Deputy": 
  {
    "name": "Deputy", 
    "message": ["Test", "Whey", "I See you!"]
  },
  "SOCO": 
  {
    "name": "SOCO",
    "message": ["Second Test", "Does this actually work?"]
  }
};

However when I go to /#/messages/Deputy I get redirected to / (There's a redirect to say to go to / if page not found)

3
  • do you have a parent states, like app and messages? Commented Apr 27, 2016 at 21:38
  • Anyway, you can here and try this to debug your routing. Hope it will help. Commented Apr 27, 2016 at 21:41
  • Could you try adding a / at the beginning of each url? Commented Apr 27, 2016 at 23:26

2 Answers 2

1

Would be nice to see the complete picture of the state hierarchy. Because this:

However when I go to /#/messages/Deputy I get redirected to / (There's a redirect to say to go to / if page not found)

could be related to parent state, which (I expect) already defines /messages

// parent
.state('app.messages', {
    url: '/messages',

// child should not repeat the parent's *url* part, it is already there
.state('app.messages.detail', {
    //url: 'messages/{id}',
    url: '/{id}',

Because without that adjustment (using doubled /messages definition) we would need url like this

/#/messages/messages/Deputy
Sign up to request clarification or add additional context in comments.

1 Comment

This worked but how would they use different templates?
0

when you run this code you should see an error like that at the console:

Cannot read property 'Deputy' of undefined

I think true message definition is should be:

$scope.message = messsages[$stateParams.id];

Comments

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.