自动将框架实用程序注入 $scope

Auto inject framework utilities into $scope

恕我直言,框架应该承担繁重的工作。依赖注入 (DI) 是 ng 中的一项重要功能。但是,它看起来很难看。同样的事情也适用于 DI。

为什么在 module.config 被调用后,不将框架实用程序 $http、$routeProvider 等注入 $scope。

不确定这是否可能? 我们现在做什么:

  phonecatApp.controller('PhoneListCtrl', function ($scope, $http) {
  $http.get('phones/phones.json').success(function(data) {
    $scope.phones = data;
  });

  $scope.orderProp = 'age';
});

VS

phonecatApp.controller('PhoneListCtrl', function ($scope) {
  $scope.$http.get('phones/phones.json').success(function(data) {
    ...
});

ng 伙计们,这是您已经准备好实施的东西吗?

我认为这不是一个好方法,$scope 旨在建立控制器和视图之间的关系,如果您将所有内容都注入 $scope 中,为什么还需要控制器?我认为这违反了 MVC 原则。