Whats the better way to identify the context path in Angular JS

后端 未结 7 1126
清酒与你
清酒与你 2021-02-05 20:38

I have my web application deployed to tomcat with an applicatio context. For example my URL looks something like this.

http://localhost:8080/myapp
7条回答
  •  無奈伤痛
    2021-02-05 21:00

    Inject the $location service to your controller.

     var path = $location.path(); // will tell you the current path
         path = path.substr(1).split('/'); // you still have to split to get the application context
    
     // path() is also a setter
     $location.path(path[0] + '/getusers');
     // $location.path() === '/myapp/getusers'
    
     // ------------------ \\
    
     // Shorter way
     $location.path($location.path() + '/getusers');
     // $location.path() === '/myapp/getusers'
    

提交回复
热议问题