3

I have an Ionic / Angular app which I have just been updating to Ionic 3 / Angular 4. I Have a couple of base classes I use for my pages...

@Injectable()
export abstract class BasePage {
  constructor(
   userMessageService: UserMessageService,
   logger: Logger,
   translate: TranslateService,    
   derivedClassName: string,    
 ) {
   super(userMessageService, logger, translate, derivedClassName);
   this.data = new Array<T>();
 }

After the upgrade, I now get the following warning..

Warning: Can't resolve all parameters for PageBase in D:/dev/myapp/src/pages/page-base.ts: ([object Object], [object Object], [object Object], ?). This will become an error in Angular v5.x

Warning: Can't resolve all parameters for CardPageBase in D:/dev/myapp/src/pages/card-page-base.ts: ([object Object], [object Object], [object Object], ?). This will become an error in Angular v5.x

So it seems it does not like the string argument. All I use this for is for some logging and I just pass it in where I instantiate a class derived from this one..

eg super(userMessageService, logger, translate, 'MyPage');

Does anyone know why this looks like it is not going to be possible, and also how can I now pass in such an argument (hopefully without having to have a separate setter of init method)

Thanks in advance for any help!

peterc
  • 6,921
  • 9
  • 65
  • 131
  • Works fine here. Post a complete minimal example reproducing the problem. http://plnkr.co/edit/tJjTaU32UTddWjSbInJL?p=preview – JB Nizet May 14 '17 at 08:48
  • You could check the InjectionToken: https://angular.io/docs/ts/latest/guide/dependency-injection.html#!#non-class-dependencies, similar question here: http://stackoverflow.com/questions/39344266/how-do-i-get-angular2-dependency-injection-to-work-with-value-providers – eko May 14 '17 at 08:55
  • are you using barrel to import services? – Aravind May 14 '17 at 11:05

1 Answers1

6

Found my problem. I thought you needed an @Injectable() on the base Page class, for example..

    @Injectable()
    export abstract class BasePage {
      constructor(protected name : string, messageProvider : MyServiceProvider) {
        console.log("Baseclass calls " + messageProvider.getMessage());
      }
    }

When I removed this it all still worked fine and the errors were gone. I should have included the class def in the original question (which I will now add)

peterc
  • 6,921
  • 9
  • 65
  • 131
  • 1
    I know it is frowned upon to comment a thank you comment, but this really helped me. Thank you for posting your own solution as an answer :D – Chris Oct 12 '17 at 10:49