使用依赖关系注入将参数传递给命名函数

Passing Parameter to a Named Function with Dependency Injection

本文关键字:函数 参数传递 依赖 关系 注入      更新时间:2023-09-26

我有一个角度应用程序,我正在将命名函数传递到控制器中。问题是我想将提供程序注入该控制器以供使用。控制台给了我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();
}