angular - Error: Uncaught (in promise): Error: No value accessor for form control with name: 'firstname'
问题描述
As i'm trying to use the template driven approach in angular 10 ionic to access the model which gives error on page load.
Now as i have used this approach in the HTML page as.
<form (ngSubmit)="onBookPlace()" #f="ngForm">
<ion-grid>
<ion-row>
<ion-col size-sm="6" offset-sm="3">
<ion-item>
<ion-label position="floating">First Name</ion-label>
<ion-text type="text" name="firstname" ngModel required></ion-text>
</ion-item>
</ion-col>
</ion-row>
<ion-row>
<ion-col size-sm="6" offset-sm="3">
<ion-item>
<ion-label position="floating">Last Name</ion-label>
<ion-text type="text" name="lastname" ngModel required></ion-text>
</ion-item>
</ion-col>
</ion-row>
</ion-grid>
</form>
What am i missing here .. ?
Update 1:
It states here as well
https://codecraft.tv/courses/angular/forms/template-driven/
解决方案
您没有正确使用 2 向绑定。用于 2 路数据绑定的 sytex 涉及 Banana-in-box 语法 [(ngModel )] ="yourVariable"。
如果要将 firstName 和 lastName 的值绑定到组件变量,则需要遵循这种 2-way 绑定语法。
https://codecraft.tv/courses/angular/forms/template-driven/#_two_way_data_binding
推荐阅读
- python - 获取您回复的消息的消息对象 (Discord.py)
- language-agnostic - Python - 用(IPv4 plus GeoIP)迭代和替换(IPv4)
- amazon-web-services - 使用 Multer 和 nodejs 上传图像而不存储它
- php - 如何访问本地文件?
- python - 当用户在他的个人资料中更改他的电子邮件时,有没有办法确认用户电子邮件 - django
- r - How can I convert a list of data frames into a data frame of lists using purrr or tidyr?
- typescript - Fastify: ts-node shoot error 属性 'foo' 在类型 'FastifyInstance<...>' 上不存在
- javascript - 为微型富文本编辑器创建点击弹出窗口
- typescript - ReactNative Animated.ScrollView ref TypeScript 定义
- javascript - 我不确定为什么我的 Fetch-Post 请求未定义