AngularJS: Read route param from within controller

后端 未结 2 1892
迷失自我
迷失自我 2021-02-02 01:01

How can a parameter from an URL be read within an AngularJS controller?

Let\'s say I have an URL like http://localhost/var/:value and I want the value to be

2条回答
  •  生来不讨喜
    2021-02-02 01:18

    Requirements: Ensure 'ngRoute' is in your app module

    Route provider set up as: http://localhost/var/:valName
    

    Function set up as:

    function functionName($scope, $routeParams){$scope.value = $routeParams.valName;}
    

    HTML view:

    {{value['valName']}}
    

提交回复
热议问题