I'm trying to build an Angularjs application and I'm having trouble with my controller.
'use strict';
/* Controllers */
angular.module('myApp.controllers', []).
controller('AppCtrl', function ($scope, $http) {
}).
controller('indexCTRL', function ($scope) {
$http.get('/api/frettir').
success(function(data, status, headers, config) {
$scope.posts = data;
});
});
But when I run it an error appears saying $http is not defined. What can I improve?
You need to inject the $http
service in the controllers you use it. I like this very precise inline syntax which will avoid problems if your code goes through minifiers.
controller('indexCTRL', ['$scope', '$http',
function($scope, $http) {
//...your code
}
])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With