Repository navigation
Closed
Labels
area: compilerIssues related to `ngc`, Angular's template compilerIssues related to `ngc`, Angular's template compilerfreq1: lowneeds reproductionThis issue needs a reproduction in order for the team to investigate furtherThis issue needs a reproduction in order for the team to investigate furthertype: bug/fix
Milestone
Description
Hey,
Just tried 9.0.0-next.4 and it seems that when you have an abstract component class:
export abstract class BaseEditFormComponent {
@Input() itemId?: number;
}And then you inherit it by specific components:
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'edit-form',
templateUrl: 'edit-form.component.html'
})
export class EditFormComponent extends BaseEditFormComponent {
constructor() {
super();
}
}And use it like:
<edit-form [itemId]="itemIdProp"></edit-form>You get runtime exception such as
global-error.handler.ts:59 Application encountered an error: Error: Template error: Can't bind to 'itemId' since it isn't a known property of 'edit-form'.
at createUnknownPropertyError (core.js:12888)
at validateAgainstUnknownProperties (core.js:12827)
at elementPropertyInternal (core.js:12732)
at ɵɵproperty (core.js:19801)
at EditFormComponent(template.html:2)
at executeTemplate (core.js:12315)
at refreshView (core.js:12179)
at refreshComponent (core.js:13484)
at refreshChildComponents (core.js:11914)
at refreshView (core.js:12238)
Adding itemId property to EditFormComponent component fixes the issue and app runs as expected.
Is such behavior expected?
🌍 Your Environment
Angular Version:
Angular CLI: 8.3.2
Node: 10.16.0
OS: win32 x64
Angular: 9.0.0-next.4
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router, service-worker
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.803.2
@angular-devkit/build-angular 0.803.2
@angular-devkit/build-optimizer 0.803.2
@angular-devkit/build-webpack 0.803.2
@angular-devkit/core 8.3.2
@angular-devkit/schematics 8.3.2
@angular/cdk 8.1.4
@angular/cli 8.3.2
@angular/flex-layout 8.0.0-beta.27
@angular/material 8.1.4
@ngtools/webpack 8.3.2
@schematics/angular 8.3.2
@schematics/update 0.803.2
rxjs 6.5.2
typescript 3.5.3
webpack 4.39.2
Metadata
Metadata
Assignees
Labels
area: compilerIssues related to `ngc`, Angular's template compilerIssues related to `ngc`, Angular's template compilerfreq1: lowneeds reproductionThis issue needs a reproduction in order for the team to investigate furtherThis issue needs a reproduction in order for the team to investigate furthertype: bug/fix
Activity
AndrewKushnir commentedon Sep 3, 2019
Hi @Enngage,
With Ivy, base classes should also be annotated using
@Directive()decorator. There is a migration that should help transition existing code to the new pattern.Please try to add the
@Directive()decorator to the base class and let us know if that fixes the problem.Thank you.
Enngage commentedon Sep 4, 2019
Hi @AndrewKushnir,
Tried adding
Directiveto my base class such as:But then my app won't start due to this error :/
Not sure if that is relevant, but I do have dependencies injected into my component which are passed to base class via
supercall.AndrewKushnir commentedon Sep 13, 2019
Hi @Enngage,
I tried to reproduce the problem locally, but failed. Here is my TestBed test (which is passing):
Could you please have a look at the test and let me know how it should be changed to better mimic your use-case and repro the problem?
Thank you.
Ristaaf commentedon Oct 17, 2019
I have the same problem (in our giant codebase with lots of abstract component classes)
Not sure why the testbed above works, but this is my simplest possible reproduction:
Using @angular/cli@next I do an ng new and then:
app.component.ts
car.component.ts
app.module.ts
And then run
ng buildWithout ivy it builds fine, with ivy I get:
AndrewKushnir commentedon Oct 17, 2019
@Ristaaf thanks for additional information. It looks like PR #33131 should fix this problem. Thank you.
alxhub commentedon Oct 28, 2019
This was resolved in #33131 :D
Enngage commentedon Nov 1, 2019
@AndrewKushnir, thanks! Yeah, that indeed fixed the issue I initially raised but wasn't able to easily reproduce due to the huge code base I have.
Though it raised another issue. I'm looking at https://next.angular.io/guide/migration-undecorated-classes which explains the change and it makes sense.
However, the compiler failes with
If you have a constructor with dependencies that cannot be resolved. In my case I have constructor in my abstract class like:
dependenciesandcdrare resolved correctly, but theconfigisn't because child class explicitely sets config in thesupercall.I'm guessing that ignoring that property would work? Is there a way to ignore it?
Edit:
Seems like using
Optional()does the trick :-)angular-automatic-lock-bot commentedon Dec 2, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.