1

I have an angular controller wrote in typescript and declared this way

angular.module('myApp').controller("gestioneProgetto",     
 ["$scope", "PalmariService", "SoluzioniService", "ProgettoService", "WmsService", "BingService", "$modal", "SettoreService",  
  ($scope, dispositivi, soluzioni, progetti, wms, bing, modal, settore)     
=> new Palmare.Controllers.gestioneProgetto($scope, dispositivi, soluzioni, progetti, wms, bing, modal, settore)])

and is working fine. I want to change removing from here the di references, moving to

static $inject = ["$scope", "PalmariService", "SoluzioniService", "ProgettoService"
                 , "WmsService", "BingService", "$modal", "SettoreService"]; 

and changing to

angular.module('myApp').controller("gestioneProgetto", ($scope, dispositivi, soluzioni, progetti, wms, bing, modal, settore)
    => new Palmare.Controllers.gestioneProgetto($scope, dispositivi, soluzioni, progetti, wms, bing, modal, settore));

this approach worked fine with all the factoriesI changes, but trying with the first controller doing this I obtain the message

Error: [$injector:unpr] Unknown provider: dispositiviProvider <- dispositivi

Am I missing something?

2 Answers 2

1

In case your definition is like this:

module Palmare.Controllers
{
    export class gestioneProgetto
    {
        static $inject = ["$scope", "PalmariService", "SoluzioniService", ...]; 
        ...

This should work for angular:

angular
  .module('myApp')
  .controller("gestioneProgetto", Palmare.Controllers.gestioneProgetto);
Sign up to request clarification or add additional context in comments.

Comments

1

To add to Radim's correct answer, the reason this is happening is because Angular is looking for the $inject property on the object that is passed as the second argument to controller.

In this case, the argument you have here:

angular
    .module('myApp')
    .controller("gestioneProgetto", ($scope, ... settore) => new Palmare.Controllers.gestioneProgetto($scope, ... settore));

is an anonymous function that doesn't have a $inject property. If you pass the controller constructor function itself, that constructor function does have the $inject property (because static members of a class appear as properties on the constructor function itself).

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.