Base solution for your next web application
Open Closed

AngularJS's "Resolve" in State does not inject to controller #981


User avatar
0
mengvisal created
Support Team

Hi!

I am trying to resolve a service using web api dynamic in resolve before loading the controller but somehow the resolve data does not inject to the controller. Do you have any clue?

Best,

Visal


4 Answer(s)
  • User Avatar
    0
    mengvisal created
    Support Team

    Hi!

    As I found out, to pass the resolved data to a controller, i should avoid using ng-controller in view. Instead, i should define the controller in state provider. I want to know is it a good practice? and is there any other works around since your project is using ng-controller rather defining the controller in the provider?

    Best,

    Visal

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Your solution seems fine. angular has many ways of doing same thing but actually I don't know any other way of it.

  • User Avatar
    0
    mengvisal created
    Support Team

    Hi! Honestly, I wanna validate a function on get request in SPA and I am doing on resolve. Do you know if it is the best solution to do it? Example, when deleting an organization unit, the user enters the delete url with Id param. For this case, I need to validate on server side to see if the organization unit is allowed to delete or the organization still exists (not yet deleted). If not allowed or not exist, i will reroute the user to another page. I do not want to validate in controller load because i do not want the controller view content to load. That's why I am doing in resolve. I am curious if you have another solution for this.

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    This is a topic related to angularjs. You can find more resource on the web or can ask on stackoverflow. As I know, you may do it in some statechange (or state activation) event in the angular. In this event, you can make an ajax request to decide it. Some such events can accept promises. As I say, you can find something on the web, I don't know exactly it.