I'm going to get some data from server using $http and JSON response. $http.get() are called after route change. But template are changed before data is downloaded. My goal is:
- User press a hyperlink in menu, that changes a route,
- Shows Loading Spinner (DOM Element is in another controller which is on page everytime)
- Initializing $scope.init()(viang-init="init()") in controller which is in my new template, this also initializing get data from server
- Data are downloaded, now I can hide spinner and change visible template
How can I do this? My App looks for example:
Javascript:
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function($scope, $http) {
    $scope.init = function() {
       $http({method: 'GET', url: 'http://ip.jsontest.com/'}).success(function(data) {
           console.log(data);
               $scope.ip = data.ip;
           });
    }
});
myApp.config(function($routeProvider) {
    $routeProvider.when('/link', {
        controller: 'MyCtrl',
        templateUrl: 'embeded.tpl.html'
    });
});
HTML:
<script type="text/ng-template" id="embeded.tpl.html">
    <div ng-controller="MyCtrl" ng-init="init()">
    Your IP Address is: {{ip}}
    </div>
</script>
<div>
    <ul>
        <li><a href="#/link">change route</a></li>
    </ul>
    <div ng-view></div>
</div>
 
     
     
    