Answer the question
In order to leave comments, you need to log in
Resolve after .success?
Good time of the day.
Please tell me how to load the controller only after the response comes from the server.
Our App.js
...
$routeProvider.when('/', {
templateUrl: 'views/home.html',
controller: 'HomePageCtrl',
resolve: // что необходимо вставить?
...
angular.module('someApp').controller('HomePageCtrl', ['$scope', '$http', function($scope, $http){
$http.get("/data").success(function(data){
$scope.data = data;
});
}]);
Answer the question
In order to leave comments, you need to log in
The resolver must receive a Promise object.
For example:
resolve: {
data: ['loader', function(loader) {
// метод, выполняющий запрос к серверу
return loader.load();
}],
}
...
$routeProvider.when('/', {
templateUrl: 'views/home.html',
controller: 'HomePageCtrl',
resolve:
{
loadedContent: ['$http', function($http) {
return $http.get('/data');
}],
}
...
angular.module('someApp').controller('HomePageCtrl', ['$scope', 'loadedContent', function($scope, loadedContent){
$scope.data = loadedContent;
}]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question