javascript - Unable to inject `$http` using AngularJS explicit `app.controller` syntax? -


i have been told should using app.controller syntax, in order support minification.

rewriting sample (tutorial) example, , found couldn't work:

use 'strict';  /* minifiable solution; doesn't work */ var app = angular.module('myapp', ['nggrid']);  // phones.json: http://angular.github.io/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; 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 echo of above line, rather content --> 

what need change?

the way did controller layout is:

var app = angular.module('myapp', ['controllers', 'otherdependencies']); var controllers = angular.module('controllers', []); controllers.controller('phonelistctrl', ['$scope', '$http', function ($scope, $http) {   // code   $http.get('phones/phones.json').success(function (data) {     $scope.phones = data;   }); }]); 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -