代码之家  ›  专栏  ›  技术社区  ›  JohnDoe

在文本输入中呈现ngModel

  •  0
  • JohnDoe  · 技术社区  · 6 年前

    我无法在输入表单中显示数据。

     <div class="input-group mb-3">
          <div class="input-group-prepend">
            <span class="input-group-text text-white" style="background-color:#03a9f4">Product ID</span>
          </div>
          <input type="text" class="form-control" [(ngModel)]="productID" name="productID" readonly="true" style="background-color: white">
     </div>
    

    内部 component.ts

     private productID: string;
    
      private initData() {
        this.productID = "12345"; //TODO REST call for data
      }
    
      ngOnInit() {
        this.initData();
      }
    

    但由于某些原因,我的输入在页面加载时没有值。为什么?

    0 回复  |  直到 6 年前
        1
  •  0
  •   Sourav Dutta    6 年前

    在这里,我已经为您创建了一个stackblitz,它正在工作。

    Working Stackblitz Demo

    推荐文章