Is there a way to access the allowed state dependencies except that they inject them into the controller?

I need to access authorized data from a service or directive in order to perform some common operations throughout the application.

The only way to access authorized data is to enter it into the controller.

This is the test data that I install:

resolve: { test: function() { console.log("resolving"); return 5+2; } } 

I tried this in my controller to see what happens, but it does not work:

 $injector.invoke(function(test) { console.log("injected", test); $scope.test = test; }); 

I get:

 "Error: [$injector:unpr] Unknown provider: testProvider <- test 

So it seems that the allowed data is being transferred as local users to the invoke function on the state controller.

I also found out that I can access the permission object from state:

 $state.current.resolve 

But this is a raw permission object with no authorized data. I could call these functions to resolve the data, but I would solve the dependencies again. If there were any requests for a permission object, they would be called twice.

I just need to access the allowed values, as if I had access to data attributes or $ state.params.

+7
angularjs angular-ui-router
source share
1 answer

I finally figured it out.

You can access all allowed data through $ state. $ current object:

 $state.$current.locals.globals 
+12
source share

All Articles