Even in Angular 4.2.4 it works fine in dev mode. But when doing a prod build (ng build -prod
) it fails:
ERROR in Template parse errors:
Can't bind to 'step' since it isn't a known property of 'app-textarea-step'.
1. If 'app-textarea-step' is an Angular component and it has 'step' input,
then verify that it is part of this module.
2. If 'app-textarea-step' is a Web Component then add
'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to
suppress this message.
My component looks like:
abstract class StepComponent {
@Input() step: BaseStep;
@Output() next = new EventEmitter<string>();
@Output() answer = new EventEmitter<Answer>();
}
abstract class SingleNextStepComponent extends StepComponent {
onSubmit(answer: string) {
// ConfirmStep heeft geen answer.
if (answer) {
this.answer.emit({ question: this.step.key, value: answer });
}
const step = this.step as SingleNextStep;
this.next.emit(step.next);
}
}
// Decorator inheritance works in standard build (ng build) but fails in production build (ng build -prod)
// Workaround: inputs element on @Component that contains the inputs.....
@Component({
selector: 'app-textbox-step',
templateUrl: './textbox-step.component.html',
inputs: ['step']
})
export class TextboxStepComponent extends SingleNextStepComponent { }
@Component({
selector: 'app-textarea-step',
templateUrl: './textarea-step.component.html',
})
export class TextareaStepComponent extends SingleNextStepComponent { }
Fortunately the workaround works. The inputs a added to the TextBoxStepComponent have prevented this one to fail, falling through to the next one, not yet provided with 'inputs'.
But 'ng build' works fine without needing inputs on the @Component decorators...