search

Home  >  Q&A  >  body text

angular.js - angularjs 路由中的templateUrl如何加参数?

app.config(function($routeProvider)
{
$routeProvider.when('/project/:id',{
    templateUrl: 'project',
    controller:'projectController'
});});

我想把id传到templateUrl中,就是实际访问的是'project/id',有办法做到吗?因为此时是根据id向后台的action发请求。新手求指教。

伊谢尔伦伊谢尔伦2743 days ago629

reply all(1)I'll reply

  • PHPz

    PHPz2017-05-15 16:52:33

    Okay, I just looked at the API and tested it. It can be written directly as a function.

    app.config(function($routeProvider)
    {
    $routeProvider.when('/project/:id',{
        templateUrl: function($routeParams){return 'project/'+$routeParams.id;},
        controller:'projectController'
    });});
    

    reply
    0
  • Cancelreply