【发布时间】:2018-04-03 17:57:19
【问题描述】:
我在表单中使用了 maxlength,但它抛出了错误
ERROR TypeError: Cannot read property 'maxlength' of null
我使用 maxlength 的部分表格:
<div>
<textarea AutoExpandTextArea [inputData]='model.title' maxlength="100" class="videoTitle" name="videoTitle" id="videoTitle" #videoTitle="ngModel" placeholder="Title" [(ngModel)]="model.title" required>{{model.title}}</textarea>
<span class="text-danger" *ngIf="submitted && loginform.form.invalid && videoTitle.errors.required">Title is mandatory</span>
<span class="text-danger" *ngIf="videoTitle.dirty && videoTitle?.errors.maxlength">Maximum 100 characters are allowed</span>
<textarea AutoExpandTextArea [inputData]='model.description' maxlength="120" class="videoDescription" id="videoDescription" name="videoDescription" #videoDescription="ngModel" placeholder="Description" [(ngModel)]="model.description">{{model.description}}</textarea>
<span class="text-danger" *ngIf="videoDescription.dirty && videoDescription?.errors.maxlength">Maximum 120 characters are allowed</span>
</div>
页面加载时模型对象如下所示
this.model = {
description: '',
title: '',
}
只要我在 textarea 中输入内容,错误就会开始出现。
我有一个指令也绑定到文本区域。不确定这是否导致了问题。
【问题讨论】:
-
我不知道是不是你的错误,但是属性值不应该都用双引号吗?
-
@jonrsharpe:引号不会导致错误。
标签: angular typescript textarea maxlength