这是我的.HTML
<ion-item> <ion-label primary floating>FirsT name</ion-label> <ion-input type="text" ID="firstname" formControlname="firstname"></ion-input> </ion-item> <p *ngIf="myForm.controls.firstname.errors && myForm.controls.firstname.dirty "> <small > <strong> <i> Min 3 chars</i></strong> </small> </p>
这是我的.ts文件
this.myForm = new FormGroup({ 'firstname' : new FormControl('',[ValIDators.required,ValIDators.minLength(3),ValIDators.maxLength(10)]),'lastname' : new FormControl('',ValIDators.minLength(1),'userIDphone' : new FormControl('',ValIDators.minLength(10),'password' : new FormControl('',ValIDators.compose([ValIDators.required,ValIDators.minLength(4),ValIDators.maxLength(25),ValIDators.pattern(this.passwordRegex)])),'confirmpassword': new FormControl('',ValIDators.required),'email' : new FormControl( '',ValIDators.compose([ ValIDators.required,ValIDators.pattern(this.emailRegex) ]) ) })
当我尝试构建我的项目(`ionic build androID’)时,我在下面收到错误
Property ‘firstname’ does not exist on type ‘{ [key string]: AbstractControl; }’.
这是我的离子信息
Cordova Cli: 6.3.0 Ionic Framework Version: 2.0.0-rc.3Ionic Cli Version: 2.1.14Ionic App lib Version: 2.1.7Ionic App Scripts Version: 0.0.45ios-deploy version: Not installedios-sim version: Not installedOS: linux 4.4Node Version: v6.0.0Xcode version: Not installed解决方法 您需要以这种方式访问formControl:
myForm.controls['firstname']
将您的p标签更改为:
<p *ngIf="myForm.controls['firstname'].errors && myForm.controls['firstname'].dirty ">总结
以上是内存溢出为你收集整理的如何在离子2中的表单上显示错误消息全部内容,希望文章能够帮你解决如何在离子2中的表单上显示错误消息所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)