AngularJs Routing with parameters

后端 未结 2 1712
执笔经年
执笔经年 2021-01-11 12:33

Can someone explain how I can route to a Url using parameters?

E.g. id like to click on a product and open more info of the product by Id.

My Routing so far

相关标签:
2条回答
  • 2021-01-11 13:28

    I thinks this issue is duplicate, see response How to pass parameters using ui-sref in ui-router to controller

    you can send paramters to state name as home({foo: 'fooVal1', bar: 'barVal1'}) with a url '/:foo?bar' see this exemple:

    $stateProvider
        .state('home', {
          url: '/:foo?bar',
          views: {
            '': {
              templateUrl: 'tpl.home.html',
              controller: 'MainRootCtrl'
    
            },
            ...
          }
    

    and send values as:

    <a ui-sref="home({foo: 'fooVal1', bar: 'barVal1'})">
    
    0 讨论(0)
  • 2021-01-11 13:38

    2 things, but you are basically there.

    First you are missing a slash before the URL param. Happens to the best of us.

    routeProvider.when("/product/:id", {
        templateUrl: "../app/views/product.html"
    });
    

    Secondly you should use ng-href instead href when you have dynamic URL params.

    <a ng-href="#/product/{{item.id}}">More Info</a>
    
    0 讨论(0)
提交回复
热议问题