我有一个角度应用程序,正在将一个命名函数传递给控制器​​。问题是我想将提供程序注入该控制器以使用。控制台给了我TypeError: object is not a function

我的问题是,我的语法出了什么问题?我在想这是错误的方式吗?

(function() {
  'use strict';

  angular.module('MyCoolApp.controllers')

  .controller('SignInCtrl', ['$scope', 'Avatar', SignInCtrl]);

  function SignInCtrl(Avatar) {
    var vm = this;

    // Error occurs here in reference to creating an instance of Avatar
    vm.avatar = new Avatar();
  }
})();

最佳答案

第一个参数是$scope而不是Avatar

function SignInCtrl($scope, Avatar) {
    var vm = this;

    // Error occurs here in reference to creating an instance of Avatar
    vm.avatar = new Avatar();
}

09-11 17:58
查看更多