【问题标题】:MEAN-stack binding from Angular does not work来自 Angular 的 MEAN 堆栈绑定不起作用
【发布时间】:2021-01-10 07:59:04
【问题描述】:

我在 login.component.ts:

type: String;
typesOfUsers = [{ name: 'kupac' }, { name: 'admin' }];

在 login.component.html 中:

<select [(ngModel)]="type">
       <option *ngFor="let t of typesOfUsers" [ngValue]="t.name">
            {{t.name}}
       </option>
</select>

但是,当我在后端记录此参数(类型)时,我得到 - 未定义。

我尝试静态绑定但结果相同。

【问题讨论】:

    标签: angularjs mean-stack


    【解决方案1】:

    我刚刚在 HTML 的 select 组件中添加了 name 属性,它可以工作:

    <select [(ngModel)]="type" name="type">
           <option *ngFor="let t of typesOfUsers" [ngValue]="t.name">
                  {{t.name}}
           </option>
    </select>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-17
      • 2014-08-05
      • 2017-11-12
      • 2012-03-22
      • 2017-06-24
      • 2017-10-06
      • 2014-09-06
      相关资源
      最近更新 更多