如何解决如何在p日历角度中设置属性值?
我正在使用p日历进行日期选择。现在,我想基于条件设置类属性。对于set属性,我正在使用setElementAttribute函数,但是它给了我错误'vendor.bundle.js:70655 TypeError: Cannot read property 'setAttribute' of undefined '
。它适用于普通输入或选择标签,但不适用于p日历标签。
这是HTML代码
<p-calendar [showIcon]="true"
name="date"
id="dateId"
#date
[(ngModel)]="dateValue"
[required]="isRequired"
autoClear="true"
(onSelect)="selectedDate(date.value)"
[ngModelOptions]="{standalone: true}"
(data)="refreshValue($event)"
dateFormat="mm/dd/yy"
hourFormat="24">
</p-calendar>
这是ts文件代码
@ViewChild('date ') date : any;
selectedDate(date) {
if (date != null) {
this._renderer.setElementAttribute(this.date.nativeElement,'class','form-control ng-pristine ng-valid ng-touched');
} else {
if(this.isRequired){
this._renderer.setElementAttribute(this.date.nativeElement,'form-control ng-touched ng-dirty ng-invalid');
this.Flag = false;
}
}
}
这是错误
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。