Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 模态-角度中的双向绑定变量_Javascript_Jquery_Angular - Fatal编程技术网

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
属性会导致这个问题。谢谢