2

Here is the code that I am using currently:

in view:

<a ui-sref="restaurantDetail({ type: {{restaurant.type}} })" >{{restaurant.name}}</a>

In route,

 .state('restaurantDetail', {
    url: '/restaurantDetail/:type',
    templateUrl: 'templates/restaurantDetail.html',
    controller : 'restaurantDetailCtrl'
  })

In controller:

.controller('restaurantDetailCtrl', function($scope,$http,Base_URL,$state, $stateParams) {   
  console.log($stateParams); //returns Object type:""
  console.log($stateParams.type); //returns undefined
});

It should generate the URL restaurantDetail/type but it is returning restaurantDetail

I don't know where the issue is? I just need to pass the variable within url using $stateProvider

3 Answers 3

1

It should be

restaurantDetail({ type: restaurant.type })
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for replying,It didn't return me the resturant.type
Here is the solution that works for me, hope it help others too. .state('menu.restaurantDetail', { url: '/restaurantDetail/:type', views: { 'side-menu21': { templateUrl: 'templates/restaurantDetail.html', controller: 'restaurantDetailCtrl' } } }) and the anchor tag is <a ui-sref="menu.restaurantDetail({ type: restaurant.type })">{{restaurant.name}}</a>
0

AS you are not passing data correctly it should be in this way

<a ui-sref="restaurantDetail({ type: restaurant.type })">{{restaurant.name}}</a>

Comments

0

I found the solution. Here is the code:

In route:

.state('menu.restaurantDetail', {
    url: '/restaurantDetail/:num',
    views: {
      'side-menu21': {
        templateUrl: 'templates/restaurantDetail.html',
        controller: 'restaurantDetailCtrl'
      }
    }
  })

in View:

<a ui-sref="menu.restaurantDetail({ num: restaurant.num })">{{restaurant.name}}</a>

Then In controller you can use $stateParams

console.log($stateParams.num);

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.