I have 2 routes sharing a controller, data is required before loading the view, and others do not need the allowed data.
An example of a routing segment:
... when('/users', { controller: 'UsersCtrl', templateUrl: '/partials/users/view.html', resolve: { resolvedData : ['Accounts', function(Accounts) { return Accounts.get(); }] } }). when('/users/add', { controller: 'UsersCtrl', templateUrl: '/partials/users/add.html' }) ...
Controller example:
app.controller('UsersCtrl', ['$scope', 'Helper', 'resolvedData', function($scope, Helper, resolvedData) {
Is there a way to get resolvedData in the controller without explicitly using the solution name as a dependency? So check can be performed?
Using $ injector does not work. I would like to do something similar to:
if ($injector.has('resolveData')) { var resolveData = $injector.get('resolveData'); }
However, this does not work even for a route with the set resolveData ('/ users'):
app.controller('UsersCtrl', ['$scope', 'Helper', '$injector', function($scope, Helper, $injector) {
Can this be done in angularjs? Or should I just create a new controller?
Thanks.
javascript angularjs
Alexandrin Rus
source share