0

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();
  }
})();
3
  • Arguments in the DI list must match number and order in the constructor. Commented Dec 30, 2014 at 21:18
  • I've seen it where $scope is not required as a parameter in the named function. Am I wrong? Commented Dec 30, 2014 at 21:19
  • You should read this Commented Dec 30, 2014 at 21:21

1 Answer 1

1

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();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.