【问题标题】:primeNg p-RadioButton value not changing htmlprimeNg p-RadioButton 值不改变 html
【发布时间】:2019-10-18 21:39:40
【问题描述】:

我有以下单选按钮:

     <div class="nextgen-goal-overall-radiobuttons pull-left">
       <label class="nextgen-input-label">Overall Goal</label>
         <div class="radio-button-item pull-left" *ngFor="let goalType of goalTypesRadioButton">
          <p-radioButton  class="nextgen-radio-button" name="{{goalType.id}}" value="{{goalType.id}}" label="{{goalType.description}}" [(ngModel)]="selectedGoalTypeId"></p-radioButton>
         </div>
     </div>

当我单击任何单选按钮时,selectedGoalTypeId 会更新为相应的值。

我的问题是在我的HTML 上我有以下条件divs

  <div class="nextgen-input-container nextgen-goal-input pull-left">
          <span *ngIf="selectedGoalTypeId === 1" class="goals-currency-icon">{{currencyFormat}}</span>
        <label class="nextgen-input-label nextgen-target-group-label">{{selectedGoalTypeId}}</label>
        <input class="nextgen-input" [class.nextgen-input-budget] = "selectedGoalTypeId === 1" type="number" pInputText placeholder="">
      </div>
      <div *ngIf="selectedGoalTypeId === 3" class="nextgen-goal-frequency-dropdown pull-left">
        <label class="nextgen-input-label nextgen-target-group-label">Frequency</label>
        <p-dropdown [showTransitionOptions]="'0ms'" [hideTransitionOptions]="'0ms'" dropdownIcon="fa fa-angle-down" class= "nextgen-dropdown" [options]="FrequencyLookup" [(ngModel)]="selectedFrequency" value="selectedFrequency"></p-dropdown>
      </div>

询问selectedGoalTypeId 是 1 还是 3,它会显示一些 div。

这里的问题是selectedGoalTypeId 更新正确。我在HTML 上贴了一些标签来检查。但是尽管selectedGoalTypeId 的值,div 不会根据它始终显示相同的条件进行更改。我在这里缺少什么?

【问题讨论】:

  • goalType.idselectedGoalTypeId 的类型匹配吗?

标签: html angular radio-button primeng


【解决方案1】:

p-radioButton 中将value="{{goalType.id}}" 更改为[value]="goalType.id"

而且我认为*ngIf="selectedGoalTypeId === 1" 应该放在上面的 div 上,而不是放在 span 上

发布解决方案Here

PS:我猜goalType.idselectedGoalTypeId 都是number

【讨论】:

  • 我用 == 而不是 === 并且工作了你的评论让我意识到问题就在那里,非常感谢!
  • 您应该对齐goalType.idselectedGoalTypeId 的类型,仍然使用=== 并正确绑定单选按钮的value 属性,如上所述
猜你喜欢
  • 2019-02-22
  • 1970-01-01
  • 2023-01-18
  • 2017-10-30
  • 2018-08-28
  • 2018-09-19
  • 2016-11-01
  • 2022-11-04
  • 1970-01-01
相关资源
最近更新 更多