window onload with angularjs ??

3,022 views
Skip to first unread message

biloki

unread,
Jan 27, 2014, 8:51:12 AM1/27/14
to ang...@googlegroups.com
Hi everyone, I want to load data by ajax in my app after html is loaded. 

Normally with jquery I do like that $(function() { // Handler for .ready() called. }); 

or window.onload with the pure javascript. 

But I don't see in the angular doc that talks about this function. 

Someone can help me how to do with angularjs Thank you

Stephen Friedrich

unread,
Jan 27, 2014, 9:41:04 AM1/27/14
to ang...@googlegroups.com
If you really need the data to be loaded right after start, regardless of any controller/scope, then you can use

angular.run(function ($http) {
   $http({method: 'GET', url: '/someUrl'})
      .success(function(data, status, headers, config) {
          ...
       });
})

Still it's probably better to have a service that loads and stores the data and inject the service where needed.
Reply all
Reply to author
Forward
0 new messages