本文介绍了得到了预期表达式的插值 ({{}})的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 HTML,但出现异常.如何解决?
解析器错误:在需要表达式的地方得到了插值 ({{}})在第 48 列[!(editForm.controls.field_item_exportExpression_{{i}}?.dirty &&editForm.controls.field_item_exportExpression_{{i}}?.invalid)]
<label class="form-control-label" for="field_exportExpression">exportExpression</label><input class="form-control" type="text" id="field_item_exportExpression_{{i}}" name="item_exportExpression_{{i}}" [(ngModel)]="datatype.items[i].exportExpression" 必需的><div [hidden]="!(editForm.controls.field_item_exportExpression_{{i}}?.dirty &&editForm.controls.field_item_exportExpression_{{i}}?.invalid)"><small class="form-text text-danger" [hidden]="!editForm.controls.field_item_exportExpression_{{i}}?.errors?.required" dpTranslate="dataconfiguration.validation.required">这个字段是必需的.</小>
以下不起作用.说找到了不需要的令牌 [
.
[hidden]="!editForm.controls.['item_exportExpression_' + i]?.errors?.required
下面不是在抱怨[
,而是在抱怨Cannot read property '0' of undefined
[hidden]="!editForm.controls.item_exportExpression_[ i]?.errors?.required
解决方案
模板
<small class="form-text text-danger" [hidden]="isRequiredError(i, 'item_exportExpression_')" dpTranslate="dataconfiguration.validation.required">这个字段是必需的.</小>
组件
checkIfInvalid( index: number, field: string ): boolean {const control = this.getControl( index, field );if ( control && control.dirty && !control.valid ) {返回真;}返回假;}isRequiredError( index: number, field?: string ): boolean {const control = this.getControl( index, field );if ( control && control.getError( "required" ) ) {返回真;}返回假;}
I have the following HTML but i get the the exception. How to fix it ?
<div class="form-group">
<label class="form-control-label" for="field_exportExpression">exportExpression</label>
<input class="form-control" type="text" id="field_item_exportExpression_{{i}}" name="item_exportExpression_{{i}}" [(ngModel)]="datatype.items[i].exportExpression" required>
<div [hidden]="!(editForm.controls.field_item_exportExpression_{{i}}?.dirty && editForm.controls.field_item_exportExpression_{{i}}?.invalid)">
<small class="form-text text-danger" [hidden]="!editForm.controls.field_item_exportExpression_{{i}}?.errors?.required" dpTranslate="dataconfiguration.validation.required"> This field is
required. </small>
</div>
</div>
The following is not working. Saying unwanted token [
found.
[hidden]="!editForm.controls.['item_exportExpression_' + i]?.errors?.required
The following is not complaining about [
but complaining Cannot read property '0' of undefined
[hidden]="!editForm.controls.item_exportExpression_[ i]?.errors?.required
解决方案
template
<div [hidden]="!checkIfInvalid(i, 'item_exportExpression_')">
<small class="form-text text-danger" [hidden]="isRequiredError(i, 'item_exportExpression_')" dpTranslate="dataconfiguration.validation.required"> This field is
required. </small>
</div>
component
checkIfInvalid( index: number, field: string ): boolean {
const control = this.getControl( index, field );
if ( control && control.dirty && !control.valid ) {
return true;
}
return false;
}
isRequiredError( index: number, field?: string ): boolean {
const control = this.getControl( index, field );
if ( control && control.getError( "required" ) ) {
return true;
}
return false;
}
这篇关于得到了预期表达式的插值 ({{}})的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!