Angular 2- 错误无法分配给引用或变量
Angular 2- Error Cannot assign to a reference or variable
我正在使用 Angular 2。我有 2 个嵌套 ng-template
,如下所示:
<ng-template ngFor let-support [ngForOf]="support">
<div class="row">
<div class="col-sm-3">
<div class="form-group form-float">
<div class="form-line focused">
<select [ngModelOptions]="{standalone: true}" [(ngModel)]="support.option" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<label class="form-label">Option</label>
</div>
</div>
</div>
<div class="col-sm-3">
<ng-template ngFor let-op3 [ngForOf]="support.option3">
<select [ngModelOptions]="{standalone: true}" [(ngModel)]="op3" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<label class="form-label">Option3</label>
</ng-template>
</div>
</div>
</ng-template>
没有内部 ng-template
也能正常工作。使用内部循环会引发以下错误:
core.js:1449 ERROR Error: Uncaught (in promise): Error: Cannot assign
to a reference or variable! Error: Cannot assign to a reference or
variable!
支持模型如下:
{
"support": [
{
"option": "string",
"option2": "string",
"option3": ["string"]
}
]
}
刚找到!我不得不将内部绑定更改为:
<ng-template ngFor let-op3 [ngForOf]="support.option3" let-op3Index="index2">
<div class="row">
<div class="form-group form-float">
<div class="form-line focused">
<select [ngModelOptions]="{standalone: true}" [(ngModel)]="op3[index2]" class="form-control">
<option value="xxx">xxx</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<label class="form-label">Option3</label>
</div>
</div>
</div>
</ng-template>
我遇到的由我的 ng-template 名字引起的错误
与另一个 ngModel 参数名称相同。
<ng-template #test></ng-template>
<xx [(ngModel)]="test">
更改模板名称有效
我正在使用 Angular 2。我有 2 个嵌套 ng-template
,如下所示:
<ng-template ngFor let-support [ngForOf]="support">
<div class="row">
<div class="col-sm-3">
<div class="form-group form-float">
<div class="form-line focused">
<select [ngModelOptions]="{standalone: true}" [(ngModel)]="support.option" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<label class="form-label">Option</label>
</div>
</div>
</div>
<div class="col-sm-3">
<ng-template ngFor let-op3 [ngForOf]="support.option3">
<select [ngModelOptions]="{standalone: true}" [(ngModel)]="op3" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<label class="form-label">Option3</label>
</ng-template>
</div>
</div>
</ng-template>
没有内部 ng-template
也能正常工作。使用内部循环会引发以下错误:
core.js:1449 ERROR Error: Uncaught (in promise): Error: Cannot assign to a reference or variable! Error: Cannot assign to a reference or variable!
支持模型如下:
{
"support": [
{
"option": "string",
"option2": "string",
"option3": ["string"]
}
]
}
刚找到!我不得不将内部绑定更改为:
<ng-template ngFor let-op3 [ngForOf]="support.option3" let-op3Index="index2">
<div class="row">
<div class="form-group form-float">
<div class="form-line focused">
<select [ngModelOptions]="{standalone: true}" [(ngModel)]="op3[index2]" class="form-control">
<option value="xxx">xxx</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<label class="form-label">Option3</label>
</div>
</div>
</div>
</ng-template>
我遇到的由我的 ng-template 名字引起的错误
与另一个 ngModel 参数名称相同。
<ng-template #test></ng-template>
<xx [(ngModel)]="test">
更改模板名称有效