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);
        });
shamila
  • 1,280
  • 6
  • 20
  • 45
  • 1
    Refer Following Links: http://stackoverflow.com/questions/24575491/angular-ui-router-passing-data-beetween-states-with-go-function-does-not-work http://stackoverflow.com/questions/22408790/angularjs-passing-data-between-pages – Malaiyandi Murugan Feb 26 '16 at 04:45
  • I use ngRoute, I tried those before asking this question. They are not the solution for my problem. – shamila Feb 26 '16 at 04:51

3 Answers3

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.

Aman Gupta
  • 53
  • 8
0

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

 .when('/promo/:id', {
            templateUrl: 'tpl/promo.html',
            controller: 'promoController',
            activePage: 'promo'
        })
shamila
  • 1,280
  • 6
  • 20
  • 45
0

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

$routeParams.id
Aman Gupta
  • 53
  • 8