0

I have a base component class:

export abstract class BaseListComponent<GenObject extends BaseObject> 
{

    constructor(
        @Inject(ActivatedRoute) protected readonly route: ActivatedRoute,
        @Inject(SpudService) protected readonly spud_service: SpudService,
    ) {
        console.log(this.route, this.spud_service);
    }

...
}

This is used by a number of classes that inherit from this one, e.g:

@Component({
    selector: 'album_list',
    templateUrl: './base-list.component.html',
})
export class AlbumListComponent extends BaseListComponent<AlbumObject> 
{
    ...
}

When I run this code using ng serve and test everything works perfectly. If I build the code with ng build and copy the dist directory to an Apache server, the constructor is called without the 2 required arguments. The call to console.log() prints undefined twice. This then results in expected fatal errors when my code tries to use these services that weren't supplied.

I also tried creating a simple test case using plunker, it works perfectly.

If in AlbumListComponent I defined a constructor with all the required injectors, it also works perfectly.

   constructor(
        @Inject(ActivatedRoute) route: ActivatedRoute,
        @Inject(SpudService) spud_service: SpudService,
    ) {
        super(route, spud_service);
        console.log(this.route, this.spud_service);
    }

However my understanding is that this should not be required. The constructor class and arguments from the parent class should be used - as I have not overridden it in the derived class.

In Chrome, if I set a break point on the console.log in the parent class, and look up the stack trace, I can see a function call where it looks like the parameters really are not being supplied:

function Wrapper_AlbumListComponent() {
  var self = this;
  self._changed = false;
  self._changes = {};
  self.context = new jit_AlbumListComponent0();
  self._expr_0 = jit_CD_INIT_VALUE1;
  self._expr_1 = jit_CD_INIT_VALUE1;
}

Any ideas where I am going wrong?

The full code is available.

Penguin Brian
  • 1,991
  • 14
  • 25
  • http://stackoverflow.com/a/42949015/1876949, https://github.com/angular/angular/issues/15004 – Sasxa Apr 02 '17 at 08:13
  • The first reference, http://stackoverflow.com/a/42949015/1876949 - is a different situation - where the router is supplied, but not working as expected. Here none of the services - including the router - are supplied to the component. The github reference looks completely unrelated, and doesn't even mention component constructors. – Penguin Brian Apr 03 '17 at 05:44

0 Answers0