1

I am new in angular.js

in my angular run method, there is api request from server side and that received data is assigned in angular.constant

angular.constant is used in my directive and that directive is used in my html page.

when my application run everything works properly but the issue is that when application is reloaded that time html page and run method's api call execute simultaneously. so the issue is that my html page directive is called first and after that data is received from server. so in that directive angular.constant value is null and directive behavior is not proper because of null value of angular.constant

Is there any solution in which when data comes from server side after that html DOM render?

thanks in advance.

2 Answers 2

1

Something like

angular.module('MyApp', [])
.controller('myController', function ($scope, $html) {
  $http.get('/some-url')
    .success(function (data) {
      // Do whatever you need to do with `data`
    });
});

This should load the controller first THEN make a call to /some-url for data.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use resolve with your route bound to your controller. So controller and view will load only when route is resolved. You can have a look at $route

If you are making web service call from the controller than you can use $q and in the success of $q you can refresh your html.

Or assign html in the success call of $http.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.