1

I retrieve data from back-end and show it in a html page using a controller. When user click a certain link, the other page load according to the link id(here promo page). I want to pass the menu_id to the loading page. I use ngRoute. Below is the html code which I tried,

<li class="table-view-cell" ng-repeat="menu in menuList">
    <a class="navigate-right btn-lg" href="#{{menu.link}}/{{menu_id}}">
          <span class="{{menu.icon}}"></span>
                    {{menu.menuName}}
    </a>
</li>

Below is the routing,

mobileApp.config(function($routeProvider) {
$routeProvider
 .when('/promo/menu._id', {
            templateUrl: 'tpl/promo.html',
            controller: 'promoController',
            activePage: 'promo'
        })

Below is the controller for the promo page which I need to retrieve the menu_id,

$http.get(SERVER_URL + '/api/templates/getCategories?appId='+$rootScope.appId+'&mainId='+$routeParams.id)
        .success(function(data) {
            $scope.requestCategory = data[0];
        }).error(function(err) {
            alert('warning', "Unable to get templates", err.message);
        });
2

3 Answers 3

1
mainModule.config([function($routeProvider) {
    $routeProvider.when('/promo/:menu._Id', {
        templateUrl : 'tpl/promo.html',
        controller : 'promoController',
        activePage: 'promo' 
    }); 
}

You can define your routing like above, notice the colon before menu._Id. In your controller, you can access menu._Id using $routeParams service as follows:

$routeParams.menu._Id

Thats's it.

Sign up to request clarification or add additional context in comments.

1 Comment

Same results as before. It is not passing the menu._id
0

It started to work when I changed the routing as below,

 .when('/promo/:id', {
            templateUrl: 'tpl/promo.html',
            controller: 'promoController',
            activePage: 'promo'
        })

Comments

0

In that case you would have to do following in your controller:

$routeParams.id

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.