search

Home  >  Q&A  >  body text

angular.js - How to add parameters to templateUrl in angularjs routing?

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

I want to pass the id to templateUrl, which means that the actual access is 'project/id'. Is there a way to do it? Because at this time, a request is made to the background action based on the ID. Novice please give me advice.

伊谢尔伦伊谢尔伦2777 days ago645

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