2

I'm trying to pass two parameters via view > controller 1 > $route > controller 2.

from view 1:

<td><a href="" ng-class="getGroups({{acnOrgId}}, {{row.NetworkOrgID}})">{{row.NetworkOrgFullName}}</a></td>

from controller 1:

    $scope.getGroups = function (acnId, orgId) {
    $location.path('/Groups/' + acnId +'/'+ orgId);
}

from my routeProvider:

    $routeProvider.when('/Groups/:acnId/:orgId', {
    templateUrl: 'Pages/acn/partials/groups.html',
    controller: 'groupsController'
});

On my controller 2:

 console.log($routeParams.acnId ,  $routeParams.orgId)

My results in Console.Log are: [object Object] 164

I can do this with a single param and I actually pass the id I want to pass.

What am I doing wrong?

Thanks in advance!

3
  • Use the edit link at the bottom left instead of adding these kinds of comments. Commented Aug 21, 2015 at 18:51
  • Thanks ryanyuyu. Done. Commented Aug 21, 2015 at 18:53
  • Have a Look at ui-Router. It handles the routing as states and has this functionality built in (ui-sref directive). It also allows you to refactor your URI's much more easily. Commented Aug 21, 2015 at 19:10

2 Answers 2

1

Your ng-class should be using {{}} interpolation directive, I don't understand why you used ng-class

ng-class="getGroups(row.acnOrgId, row.NetworkOrgID)"

You redirecting purpose you could use anchor ng-href to create an href link.

<td>
   <a ng-href="/Groups/{{row.acnOrgId+'/'+row.NetworkOrgID}}">{{row.NetworkOrgFullName}}</a>
</td>
Sign up to request clarification or add additional context in comments.

5 Comments

That's embarrassing. That was supposed to be ng-click directive. Thanks Pankaj!
@crowsfeet why you wanted to do it from ng-click? any reason?
I'm passing those params to a function. What would you suggest?
That was meant to be an ng-click directive that passed two params. It was a typo. But you are right, I could just as easily use the herf. Thanks for the input!
@crowsfeet check that..if it works then do accept answer..Thanks :)
0

Apparently there are problems with the link tag and the use of service $ location.

There are two possible ways to switch from view 1 to 2:

by using ng-href: <a ng-href="/Groups/{{row.acnOrgId}}/{{row.NetworkOrgID}}">{{row.NetworkOrgFullName}}</a>

by using ng-click: <a href="" ng-click="getGroups(acnOrgId, row.NetworkOrgID)">{{row.NetworkOrgFullName}}</a>

About getGroups function. Consider that $location.path change the router to the URL passed as a parameter.

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.