-
Notifications
You must be signed in to change notification settings - Fork 25.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TemplateRef for ngModel doesn't work when nested in *ngIf #25700
Comments
Local vars (like function outter() {
function inner() {
let selectElBroken = ...;
}
// trying to access selectElBroken here won't work
} We need to have some rules for templates and keeping it in sync with JS function scoping is our guiding principle. Closing as it works as designed. |
Ok, thanks for the explanation. If I understand it correctly, it is impossible to achieve what I described? If I use your example with function scoping, would it be possible to use some something like function outer() {
let selectElBroken = null;
function inner() {
selectElBroken = ...;
}
} In language of angular templates, something like <input type="hidden" [(ngModel)]="selectedValue" #selectElBroken="ngModel" />
<ng-container *ngIf="true">
<mat-form-field>
<mat-select [(ngModel)]="selectedValue" placeholder="Select value" #selectElBroken="ngModel">
<mat-option *ngFor="let item of [1,2,3]" [value]="item">{{item}}</mat-option>
</mat-select>
</mat-form-field>
</ng-container>
{{selectElBroken?.dirty}} |
@pkozlowski-opensource Is there any workaround how to avoid this limitation? |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a...
Current behavior
Accessing
ngModel
using templateRef doesn't work when it is inside*ngIf
statement.Expected behavior
It should work.
Minimal reproduction of the problem with instructions
selectElBroken
will beundefined
https://stackblitz.com/edit/angular-rr54wp-template-form-bug
What is the motivation / use case for changing the behavior?
I need to get state of template-driven form field which is inside
*ngIf
.Environment
I'm pretty sure it is related to #8563
The text was updated successfully, but these errors were encountered: