Repository navigation
Closed
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: compilerIssues related to `ngc`, Angular's template compilercompiler: parserfreq1: lowstate: confirmedstate: has PRtype: bug/fix
Milestone
Description
🐞 bug report
Affected Package
@angular/compiler-cli or @angular/compiler ?
Is this a regression?
No
Description
I enabled strictTemplates in my project and follow this guide to fix type errors.
But when I add a non-null assertion operator to the two-way binding value, the compilation result does not meet expectations.
🔬 Minimal Reproduction
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `
<input type="checkbox" [(ngModel)]="obj.value!">
<!-- ^^^^^^^^^ -->
`,
styleUrls: ['./app.component.less']
})
export class AppComponent {
obj: {
value?: boolean
} = {}
}🔥 Exception or Error
Expected
function AppComponent_Template(rf, ctx) {
if (rf & 1) {
i0.ɵɵelementStart(0, "input", 0);
i0.ɵɵlistener("ngModelChange", function AppComponent_Template_input_ngModelChange_0_listener($event) {
return ctx.obj.value = $event;
// ^^^^^^^
});
i0.ɵɵelementEnd();
}
if (rf & 2) {
i0.ɵɵproperty("ngModel", ctx.obj.value);
}
}Actually
function AppComponent_Template(rf, ctx) {
if (rf & 1) {
i0.ɵɵelementStart(0, "input", 0);
i0.ɵɵlistener("ngModelChange", function AppComponent_Template_input_ngModelChange_0_listener($event) {
return ctx.obj.value != $event;
// ^^^^^^^^^
});
i0.ɵɵelementEnd();
}
if (rf & 2) {
i0.ɵɵproperty("ngModel", ctx.obj.value);
}
}🌍 Your Environment
Angular Version:
Angular CLI: 9.1.1
Node: 12.16.1
OS: darwin x64
Angular: 9.1.1
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.901.1
@angular-devkit/build-angular 0.901.1
@angular-devkit/build-ng-packagr 0.901.1
@angular-devkit/build-optimizer 0.901.1
@angular-devkit/build-webpack 0.901.1
@angular-devkit/core 9.1.1
@angular-devkit/schematics 9.1.1
@angular/cdk 9.2.0
@ngtools/webpack 9.1.1
@schematics/angular 9.1.1
@schematics/update 0.901.1
ng-packagr 9.1.0
rxjs 6.5.5
typescript 3.8.3
webpack 4.42.0
Anything else relevant?
Current solution
<input type="checkbox" [(ngModel)]="!!obj.value">function AppComponent_Template(rf, ctx) {
if (rf & 1) {
i0.ɵɵelementStart(0, "input", 0);
i0.ɵɵlistener("ngModelChange", function AppComponent_Template_input_ngModelChange_0_listener($event) {
return !!(ctx.obj.value = $event);
});
i0.ɵɵelementEnd();
}
if (rf & 2) {
i0.ɵɵproperty("ngModel", !!ctx.obj.value);
}
}or
<input type="checkbox" [(ngModel)]="$any(obj).value">or
<input type="checkbox" [ngModel]="obj.value!" (ngModelChange)="obj.value = $event">Reacted by Yuriy Grunin, Dmitrii Usanov, Pavel Shurygin, Konstantin Zhandov, Andrey Piskunov, Nikita Balakirev, Aleksandr Prikhodko, Sharikov Vladislav and Dmitry Vasiliev
Metadata
Metadata
Assignees
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: compilerIssues related to `ngc`, Angular's template compilercompiler: parserfreq1: lowstate: confirmedstate: has PRtype: bug/fix
Activity
JoostK commentedon Apr 12, 2020
Tracking as FW-2071
th0r commentedon Aug 25, 2021
Are there any plans to fix this issue guys? Just faced it as well.
fix(compiler): allow banana-in-a-box bindings to end with non-null as…
fix(compiler): allow banana-in-a-box bindings to end with non-null as…
angular-automatic-lock-bot commentedon Mar 10, 2022
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.