0

I'm having problem of initializing "elements" in COMPONENTS with data coming from web-request. F.e. (pseudo code) :

 <elem elemOpts="$ctrl.elemOpts" />


 .......
 ctrl = this;

 ctrl.web_data = [];
 ctrl.elemOpts = { data : ctrl.web_data }

 ctrl.$onInit = function() {
    $http({ ... }).then(function(response) {
       ctrl.web_data = response.data;
    })
 } 

This is not working, because the ELEMENT is initialized before $onInit(), so the web request comes afterwards. Is there a way to execute COMPONENT-code before elements are rendered ?

Two cases which I have this problem is ui-grid and multiselect, where I have to initialize select-boxes from web-request.

sten
  • 7,028
  • 9
  • 41
  • 63

1 Answers1

0

Fetch data from resolve in routing and inject it in controller. [this][1] explains better resolve in angular component.

Or you can use ngOnChanges event

Gourav Garg
  • 2,856
  • 11
  • 24