无法绑定角度6中的ts文件中的数据

时间:2018-09-09 06:27:15

标签: html angular6

我是Angular的新手。我想在Table中提交文本框和下拉列表数据时绑定数据。虽然在控制台中,我可以看到在文本框和下拉列表中键入的内容。这是我将Json字符串化的ts文件代码。

{
event.preventDefault();
const target = event.target;
const ddlParticulars = target.querySelector("#ddlParticulars").value;

const ddlmonth = target.querySelector("#ddlmonth").value;
 // const txtammount = target.querySelector("#txtammount").value;
const ddlaccyear = target.querySelector("#ddlaccyear").value;
const ddlcuryear = target.querySelector("#ddlcuryear").value;
this.receiptList.push({
  ddlParticulars: ddlParticulars,
//  txtammount: txtammount,
  ddlmonth: ddlmonth,
  ddlaccyear: ddlaccyear,
  ddlcuryear: ddlcuryear
});
this.receiptListJson = JSON.stringify(this.receiptList);
console.log("receiptList " + this.receiptListJson);

}

这是我的HTML

 <table class="table table-bordered">
        <thead>
          <tr>
            <th scope="col">SL#</th>
            <th scope="col">Particulars</th>
            <th scope="col">Cr.ID</th>
            <th scope="col">Ammount</th>
            <th scope="col">Month</th>
            <th scope="col">Accademic Year</th>
            <th scope="col">Current Year</th>
          </tr>
        </thead>
        <tbody>
          <tr *ngFor="let item of receiptList; index as i">
            <th scope="row">{{i+1}}</th>
            <td>{{item.ddlParticulars}}</td>
            <td>1</td>
            <td>1</td>
            <td>{{item.ddlmonth}}</td>
            <td>{{item.ddlaccyear}}</td>
            <td>{{item.ddlcuryear}}</td>

          </tr>
        </tbody>
      </table>

这里按项目和for循环,我无法在ts文件中获取该变量。请帮助我。

0 个答案:

没有答案