javascript - 如何在 ionic 3 的不同页面之间更改元素?

标签 javascript typescript ionic3

我的问题是如何在这两个页面之间交换信息的逻辑。可能吗?

检查表有效,但我不知道如何在 goToNextPage () 函数返回成功后将成功/错误图标添加到房间名称旁边的“verifyplace.html”页面。如何在不同页面之间进行这种更改?

页面如下(.html 和 .ts):

verifyplace.html:

<ion-list>
      <button ion-item (click)="openRoom()">Room</button>
</ion-list>

我的 verifyplace.ts:

openSala(){
    this.navCtrl.push(VerifyroomPage);
}

我的验证室.html:

<ion-list>
    <ion-item *ngFor="let item of checkRoom">
      <ion-label>{{ item.title }}</ion-label>
      <ion-checkbox [(ngModel)]="item.checked" color="secondary"></ion-checkbox>
    </ion-item>

    <button ion-button color="secondary" (click)="goToNextPage()" full>Finish</button>
</ion-list>

我的验证室.ts:

public checkRoom = [
        {
            title: 'Checklist 1',
            checked: false
        },
        {
            title: 'Checklist 2',
            checked: false
        },
        {
            title: 'Checklist 3',
            checked: false
        }   
    ];

    goToNextPage() {
        if (this.checkSala.filter(c=>c.checked == false).length == 0) {
            this.navCtrl.push(VerifyplacePage);
            /*return on the previous page a success icon*/
        } else {
            this.navCtrl.push(VerifyplacePage);
            /*return on the previous page an error icon*/
        }
    }

最佳答案

这是我的理解;

您在 VerifyroomPage 页面上,您希望在传递一些参数时导航到另一个页面 (VerifyplacePage)。

您可以通过将对象作为 Ionic Nav Controller 上 push 方法的第二个参数传递来实现此目的。

/*return on the previous page a success icon*/
this.navCtrl.push(VerifyplacePage, {'data': 'success'});

/*return on the previous page an error icon*/
this.navCtrl.push(VerifyplacePage, {'data': 'error'});

第 2 步:

然后在 VerifyplacePage.ts 上

// create a variable to hold the data
thePageData

...

// in the constructor
public navParams: NavParams,

...


// get the data from the nav params and save it in the local variable
// we defined data as the key in the object on the nav controller
this.thePageData = this.navParams.get('data')

Read more on Navigation within ionic 3 here

关于javascript - 如何在 ionic 3 的不同页面之间更改元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53156546/

相关文章:

javascript - 如何在 JavaScript 中链接两到三个第三方回调?

javascript - 单击时显示 FB 状态更新弹出窗口?

javascript - 如何使用语义 UI 和 AngularJS 获取选中的复选框?

css - angular - 单击 flexbox 网格单元以全宽扩展下方区域

ionic-framework - 使用包含 [virtualScroll] 属性的 ion-list 对页面进行单元测试

javascript - $timeout 之前的行不起作用(angularjs)

angular - 获取未捕获错误 : Can't resolve all parameters for

javascript - TypeScript – Visual Studio Code – 编译后不输出 2 个空格选项卡

javascript - 带有 Angular 和 ngx-gallery 的动态图像

ios - 如何在导航栏 ios 上重叠图像