Tôi có been told rằng tôi nên sử dụng cú pháp app.controller
, để hỗ trợ việc rút gọn.
Viết lại mẫu (hướng dẫn) ví dụ, và tôi thấy rằng tôi không thể làm cho nó làm việc:
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 -->
Tôi cần những gì để thay đổi?
Theo như tôi biết bạn có thể sử dụng phiên bản thứ hai ngay cả đối với giảm thiểu, vì dòng $ bơm - mà nói angular.js đúng không thay đổi tên của hai tham số. – flaschenpost
Nó hoạt động cho tôi. Lỗi bạn nhận được là gì? – DanEEStar