Angular2 ngIf停止运行

时间:2016-08-17 21:18:09

标签: angular ionic-framework ionic2

我遇到了(我相信的)更改检测的问题。请原谅我的无知,因为我对angular2有点新鲜。

所以我在视图中有以下代码。基本上它为我所引入的每个事件生成这些卡。当用户点击按钮时,* ngIf应该根据我从几个函数返回的值隐藏/显示按钮(基本上检查用户是否有已注册/点击该按钮)。

<ion-card *ngFor="let event of events" text-wrap>
                <ion-card-header>
                    <span class="title">{{event.title}}</span>
                    <span *ngIf="doesExist(event.startDate)" class="date">{{formatDateDisplay(event)}}</span>
                </ion-card-header>
                <img src='{{event.imageURL}}'/>
                <ion-card-content [innerHTML]="event.desc"></ion-card-content>

                <ion-list *ngIf="doesExist(event.sgOptions)" radio-group [ngModel]="event.sgOptions" [formControl]="sgOption">
                  <ion-list-header>
                    Select Preferred Time
                  </ion-list-header>
                  <ion-item *ngFor="let opt of event.sgOptions">
                    <ion-label>{{opt}}</ion-label>
                    <ion-radio [value]="opt" [disabled]="!isNotRegistered(event.id) && !isSudentProfileBlank()"></ion-radio>
                  </ion-item>
                </ion-list>

                <ion-buttons end>
                      <button block primary *ngIf="isNotRegistered(event.id)" (click)="submitToSheet(event.title, event.id, doesExist(event.sgOptions))">Sign Me Up</button>
                      <button block primary *ngIf="!isNotRegistered(event.id) && !isSudentProfileBlank()" disabled>Signed Up!</button>
                      <button block primary *ngIf="!isNotRegistered(event.id) && isSudentProfileBlank()" (click)="openModal()">Sign Me Up</button>
                </ion-buttons>
            </ion-card>

用户单击第一个按钮后,它会隐藏活动按钮并显示已禁用。这是预期的行为。但是,当我尝试再点击另一个时,它不会正确隐藏/显示按钮。在浏览器中检查时,* ngIf根本不再触发并检查我的功能。

任何人都知道为什么那不再适用?还有另外一种方法可以完成这项工作吗?

- 的修改 -

这是github仓库中页面的链接。它是我粘贴的代码的早期版本,但问题也存在。

https://github.com/tjohnson5/Trav-Ionic2-App1/tree/master/app/pages/register

0 个答案:

没有答案