Javascript 模态-角度中的双向绑定变量
我有一个Javascript 模态-角度中的双向绑定变量,javascript,jquery,angular,Javascript,Jquery,Angular,我有一个Bootstrap模式,我使用jQuery初始化它,如下所示: $('#saleModal').modal('show'); // I know I should use the angular way in initializing the modal but... <input type="text" [(ngModel)]="toBeBoundVariable"> 在模式中,我有一个输入,需要绑定到一个变量,如下所示: $('#saleModal').modal('
Bootstrap模式
,我使用jQuery
初始化它,如下所示:
$('#saleModal').modal('show'); // I know I should use the angular way in initializing the modal but...
<input type="text" [(ngModel)]="toBeBoundVariable">
在模式
中,我有一个输入
,需要绑定到一个变量,如下所示:
$('#saleModal').modal('show'); // I know I should use the angular way in initializing the modal but...
<input type="text" [(ngModel)]="toBeBoundVariable">
.ts
文件
import {Component, OnInit} from '@angular/core';
declare var $: any;
@Component({
selector: 'app-purchase',
templateUrl: './purchase.component.html',
styleUrls: ['./purchase.component.css']
})
export class PurchaseComponent implements OnInit {
firstname: string;
constructor() {
}
ngOnInit() {
}
showModal() {
$('#saleModal').modal('show');
}
}
我认为您没有在输入字段中添加
name
属性
<input type="text" class="form-control" [(ngModel)]="firstname" name="firstName">
希望它能解决你的问题。确保已在模块中导入FormsModule。能否共享一些您尝试过的代码,如您创建的模式组件?不要这样做。使用angular material/cdk或ng引导。@KomolNathRoy我已经用示例代码更新了问题,它成功了!我不相信缺少
name
属性会导致这个问题。谢谢