For example:
There are three controllers in the application, they are in a horizontal relationship
Controller A controls the head part of the page
Controllers B and C control the details page, edit page, routing The relationship is as follows
when('/detail/:id', { templateUrl: 'tpls/detail.html', controller: "BController" }).
when('/edit/:id', { templateUrl: 'tpls/edit.html', controller: "CController" }).
The current requirement is to obtain the parameter id in the routing URL in controller A. How to obtain it?
My current implementation:
I wrote a service and wrote a function in the service. The function of this function is to use $location.path() to get the current URL, and then use the string The interception method is used to get the id in the parameter. Although the value is obtained, it feels that it should not be this way
My attempt:
$location has an API, $location.search().name is used to get the current url parameters, but this API cannot get my parameters because my url is in the shape of index.html# In the form of /detail/1, it cannot be obtained without name
Another idea is to add a higher-level controller to the three controllers and transfer it through the parent controller, but this seems inappropriate
Can’t you put the ID in cookies
angular-ui exclusively gets $stateParams
Inject $route
and then $route.current.params is
http://stackoverflow.com/questions/25370775/exposing-the-current-state-name-with-ui-router
Inject this service into $routeParams, then