【问题标题】:List is not displayed when using *ngSwitchCase使用 *ngSwitchCase 时不显示列表
【发布时间】:2019-08-11 00:07:16
【问题描述】:

我想将 3 个按钮绑定到 3 个不同的列表。我可以使用ion-segment,但因为我喜欢分段的设计,所以我只是使用自定义按钮来完成。但是现在当我实现 *ngSwitchCase 时,当我单击按钮时,列表根本不会显示,我收到此错误 Error: No value accessor for form control with unspecified name attribute

page.html

 <ion-row [(ngModel)]="pre" [(ngModel)]="type" class="bg">
            <ion-col col-4><ion-button value="own"</ion-button></ion-col>
            <ion-col col-4><ion-button value="friends"</ion-button></ion-col>
            <ion-col col-4><ion-button value="all" </ion-button></ion-col>
          </ion-row>

 <div [ngSwitch]="pre">
      
    <ion-list  *ngSwitchCase="'own'">
   
     </ion-list>

       <ion-list  *ngSwitchCase="'friends'">
   
     </ion-list>

       <ion-list  *ngSwitchCase="'all'">
 
     </ion-list>
   
     </div>

【问题讨论】:

    标签: html angular ionic-framework


    【解决方案1】:

    这里的问题是ion-row 没有实现值访问器,这是使用ngModel 所必需的,您需要使用一个确实实现值访问器的元素。

    例如ion-segment

      <ion-segment [(ngModel)]="type" [(ngModel)]="pre">    
        <ion-segment-button value="own">
          Own
        </ion-segment-button>
        <ion-segment-button value="friends">
          Friends
        </ion-segment-button>
        <ion-segment-button value="all">
          All
        </ion-segment-button>
      </ion-segment>
    

    在一个元素上拥有两个 ngModel 很奇怪,但如果您愿意,也可以。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-18
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 2016-02-10
      • 2022-07-03
      • 1970-01-01
      相关资源
      最近更新 更多