There are two addresses in the router:

when('/:userName', { resolve: { //сюда прилетают данные только по юзеру userdata: resolves.userdata }, templateUrl: '/partials/userPage.html', controller: 'userCtrl' }). when('/magazine/:magazineName', { resolve: { //сюда прилетают данные по юзеру и журналу magazine: resolves.magazine, userdata: resolves.userdata }, templateUrl: '/partials/magazine.html', controller: 'magazineCtrl' controllerAs: 'vm', }) 

you need to combine them in one

 when('/:objName', { resolve: { magazine: resolves.magazine, userdata: resolves.userdata }, templateUrl: '/partials/magazine(userPage).html', controller: 'magazineCtrl(userCtrl)' }) 

and use parameter checking through the service, so that depending on the response of the service, the total route dynamically changes

 .service('userOrMagazine', ['$route', '$q', 'tools', function($route, $q, tools) { var params = $route.current.params, objName= params.objName? params.objName: null, q = $q.defer(); if (!objName) q.reject(); tools.data.get(api.RESOLVE.format(objName)).then(function(data) { // data.type равен 'users или 'magazines' return q.resolve(data.type); }); return q.promise; }]); 

Any thoughts on how to implement this?

  • what is meant by the general route and how should it change? - Grundy Nov.
  • the text flies into the objName parameter, the text passes through the service, and depending on whether the service gives ('users' or 'magazines') use the necessary controllers and templates - Alexander
  • with a standard router it is impossible to select a controller depending on something at the controller: 'magazineCtrl(userCtrl)' level controller: 'magazineCtrl(userCtrl)' - Grundy

0