AngularJS: how can I get $location.path to template

前端 未结 2 794
南旧
南旧 2021-02-01 12:39

I need current path from url in template (content of $location.path). But not via controller, because I have a lot of controllers (and I do not want to duplicate declaration of

2条回答
  •  不知归路
    2021-02-01 13:07

    An alternative is to use the more semantic and versatile ui-router, then in the controller, retrieve the current state, and store it on the $scope:

    app.controller('MyCtrl', ['$scope', '$state', function MyCtrl($scope, $state) {
      $scope.state = $state.current.name;
      ...
    }
    

提交回复
热议问题