How to pass URL parameters through templateUrl in AngularJS?

前端 未结 2 1456
庸人自扰
庸人自扰 2020-12-16 22:41

Trying to learn AngulareJS got stuck with this.

This is the code :

app.config(function ($routeProvider){
$routeProvider
.when(\'/\',
{       
           


        
相关标签:
2条回答
  • 2020-12-16 23:13

    Probably you are looking for $routeparams https://docs.angularjs.org/api/ngRoute/service/$routeParams.

    you can do something like below:

    app.config(function ($routeProvider){
      $routeProvider
        .when('/',{
            templateUrl: '/sort',
            controller : 'tasksController'
        })
        .when('/expression/:expressionId/type/:typeId', {
            templateUrl: '/sort',
            controller : 'tasksController'
        })
    });
    
    app.controller('tasksController', ['$scope', '$routeparams', function($scope, $routeparams) {
        var expressionId = $routeparams.expressionId
            , typeId = $routeparams.typeId;
    }]);
    
    0 讨论(0)
  • 2020-12-16 23:15

    Thanks guys,this is what I wanted

    .when('/expression/:expressionId/type/:typeId', {
    
    templateUrl: function(params) {
        return '/sort/' + params.expressionId +'/'+ params.typeId ;
    },
    controller: 'tasksController'
    });
    
    0 讨论(0)
提交回复
热议问题