Failed to enter `$ http` using the explicit` app.controller` AngularJS syntax?

I was told that I should use the app.controller syntax in order to support mini-tuning.

Rewriting an example (tutorial), and I found that I can't get it to work:

 use 'strict'; /* Minifiable solution; which doesn't work */ var app = angular.module('myApp', ['ngGrid']); // phones.json: http://angular.imtqy.com/angular-phonecat/step-5/app/phones/phones.json app.controller('PhoneListCtrl', ['$scope', '$http', function ($scope, $http) { $http.get('phones/phones.json').success(function (data) { $scope.phones = data; }); $scope.orderProp = 'age'; }]); 
 /* Alternate [textbook] solution; which works */ function PhoneListCtrl($scope, $http) { $http.get('phones/phones.json').success(function (data) { $scope.phones = data; }); $scope.orderProp = 'age'; } PhoneListCtrl.$inject = ['$scope', '$http']; 
 <body ng-app="myApp" ng-controller="PhoneListCtrl"> {{phones | json}} </body> <!-- Outputs just an echo of the above line, rather than content --> 

What do i need to change?

+8
javascript angularjs dependency-injection angularjs-scope controller
source share
1 answer

How I made my controller layout:

 var app = angular.module('myApp', ['controllers', 'otherDependencies']); var controllers = angular.module('controllers', []); controllers.controller('PhoneListCtrl', ['$scope', '$http', function ($scope, $http) { // your code $http.get('phones/phones.json').success(function (data) { $scope.phones = data; }); }]); 
+13
source

All Articles