angular - 将ngmodel添加到离子应用程序无法显示
问题描述
这是我的html页面:
<ion-header>
<ion-toolbar>
<ion-title>test</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<form (ngSubmit)="addInfo()"></form>
<ion-item>
<ion-label color="primary" floating>الاسم الاول </ion-label>
<ion-input [(ngModel)]="personal_info.first_name" name="first_name"></ion-input>
</ion-item>
<button ion-button type="submit" block>Add Todo</button>
</form>
</ion-content>
和.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-test',
templateUrl: './test.page.html',
styleUrls: ['./test.page.scss'],
})
export class TestPage implements OnInit {
public personal_info : {};
constructor() { }
ngOnInit() {
}
addInfo() {
console.log(this.personal_info)
}
}
如果我不包含 ng 模型,该页面可以正常工作,但是上面的代码我没有错误&它没有显示
解决方案
如果你想使用 ngModel 你必须将 FormModule 导入到你的 module.ts 文件中:
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
FormsModule,
],
...
推荐阅读
- excel - 尝试将值小于零的单元格格式化为逗号
- jquery - Bootrap-Select 不能在多个值上选择
- sql - 如何使用一个查询提取当前日期和下一个日期
- java - 是否可以通过 Java 中的 Telegram API 发送邮件(不是机器人)
- vb.net - 尝试使用 Blue Prism 对 HTTP 请求令牌进行 API 时出现错误“字典中不存在给定的密钥”
- python - 如何在期望脚本中读取发送命令输出
- loops - 我如何优化ansible的剧本
- prestashop - 如何在 smarty 中将点转换为逗号
- php - 当您在本地开发 Magento 时,请求需要多长时间?
- c++ - 在 CurrentProject 中使用 ExternalProject 的目标