pooja shah
pooja shah

Reputation: 341

Html render after receiving data from server in angular.js

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.

Upvotes: 1

Views: 623

Answers (2)

krish
krish

Reputation: 537

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.

Upvotes: 0

Grigor
Grigor

Reputation: 4049

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.

Upvotes: 1

Related Questions