1

I want to inject a javascript object into my controller. I decide to use "value" approach. This works:

//define a module
var mainApp = angular.module("mainApp", []);

//create a value object as "defaultInput" and pass it a data.
mainApp.value("defaultInput", 5);
...

//inject the value in the controller using its name "defaultInput"
mainApp.controller('CalcController', function($scope, CalcService, defaultInput) {
   $scope.number = defaultInput;
   ...

But as soon as i use Inline Array Annotation for controller, the defaultInput argument become underfined while controller instantiation:

mainApp.controller('CalcController', ['$scope','CalcService', function($scope, CalcService, defaultInput) {

I dont want to refuse of inline instantiation since it is recommended way accroding documentation, but can't find how to inject my object in this case. Thanks!

1 Answer 1

1

You missed to inject dependency defaultInput

mainApp.controller('CalcController',['$scope','CalcService','defaultInput',//<--inject here
   function($scope,CalcService,defaultInput) {
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.