Ho il been told che dovrei usare la sintassi app.controller
, per supportare la minificazione.
Riscrivere l'esempio del campione (tutorial), e ho scoperto che non ho potuto farlo funzionare:
use 'strict';
/* Minifiable solution; which 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; 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 -->
cosa ho bisogno di cambiare?
Per quanto ne so è possibile utilizzare la seconda versione, anche per ridurre al minimo, a causa della linea $ Inject - che racconta angular.js il corretto invariato nomi dei due parametri. – flaschenpost
Funziona per me. Qual è l'errore che hai ottenuto? – DanEEStar