use*_*066 8 javascript dependency-injection controller angularjs angularjs-scope
我被告知我应该使用app.controller语法,以支持缩小.
重写示例(教程)示例,我发现我无法使其工作:
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';
}]);
Run Code Online (Sandbox Code Playgroud)
/* 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'];
Run Code Online (Sandbox Code Playgroud)
<body ng-app="myApp" ng-controller="PhoneListCtrl">
{{phones | json}}
</body> <!-- Outputs just an echo of the above line, rather than content -->
Run Code Online (Sandbox Code Playgroud)
我需要改变什么?
Foo*_*o L 13
我做控制器布局的方式是:
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;
});
}]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13497 次 |
| 最近记录: |