thank_you
thank_you

Reputation: 11107

Passing Parameter to a Named Function with Dependency Injection

I have an angular app and I'm passing a named function into a controller. The problem is I want to inject a provider into that controller to use. The console gives me TypeError: object is not a function.

My question is, what's wrong with my syntax? Am I thinking of this the wrong way?

(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();
  }
})();

Upvotes: 0

Views: 162

Answers (1)

Oleksandr T.
Oleksandr T.

Reputation: 77482

First argument is $scope not Avatar

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

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

Upvotes: 1

Related Questions