A
A
Alexander Kovalchuk2015-07-29 15:11:57
Angular
Alexander Kovalchuk, 2015-07-29 15:11:57

How to use $http or equivalent in Angular's “Controller as” syntax?

What are the analogues, or how to include $http in Controller as syntax?
In the old version, I did this:

example.controller('exampleCtrl', [ $scope, $http, function($scope, $http) {
$http.get('/json').success(function(data, status, headers, config) {
     $scope.example = data;
   });
}]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2015-07-29
@mamut

example.controller('exampleCtrl', ['$http', function($http) {
var vm = this;
$http.get('/json').success(function(data, status, headers, config) {
     vm.example = data;
   });
}]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question