1

Having issue while routing

common.js

when('/showmessage/:groupkey/:groupmessage', {
    templateUrl: 'templates/groups/showmessage.html',
    controller: 'GroupsController'
  }).
 when('/showmessage/:groupkey/:channelmessage', {
    templateUrl: 'templates/channels/showmessage.html',
    controller: 'ChannelsController'
  }).   

index.html

<md-list-item class="md-3-line" ng-repeat="usergroup in usergroups">
<a ng-href="#/showmessage/{{usergroupkey}}/{{'groupmessage'}}">
    <img ng-src="images/abc.png" class="md-avatar">                 
</a> 
<a ng-href="#/showmessage/{{usergroupkey}}/{{'channelmessage'}}">
    <img ng-src="images/abc.png" class="md-avatar">                 
</a> 

When I click on group(1st link) it outputs grouplist page. But, when I click on channel(2nd link) it outputs grouplist page. Issue is when I am using different controllers, urls then why it is displaying same list page.

1
  • Angular's ng-router takes URL's into consideration, so in this you don't have 2 different URLs, even though param names are different. I'd suggest you to change URL or use ui-router for routing. Something like showgroupmessage and showchannelmessage Commented Apr 15, 2016 at 13:29

2 Answers 2

1

To complete Antenka answer here is how you should write things :

when('/showmessage/groupmessage/:groupkey', {
    templateUrl: 'templates/groups/showmessage.html',
    controller: 'GroupsController'
  }).
when('/showmessage/channelmessage/:groupkey', {
    templateUrl: 'templates/channels/showmessage.html',
    controller: 'ChannelsController'
}). 

Usage :

<md-list-item class="md-3-line" ng-repeat="usergroup in usergroups">
<a ng-href="#/showmessage/groupmessage/{{usergroupkey}}">
    <img ng-src="images/abc.png" class="md-avatar">                 
</a> 
<a ng-href="#/showmessage/channelmessage/{{usergroupkey}}">
    <img ng-src="images/abc.png" class="md-avatar">                 
</a> 
Sign up to request clarification or add additional context in comments.

Comments

0

It happens because your query matched at the 1st route, so it won't proceed to the next one. Giving different names to the params, doesn't give you different URLs.

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.