简体   繁体   English

将另一个来自Ionic 3列表的项目显示到另一页

[英]Display to another page one item comming from an list in Ionic 3

According to ionic project, I display a list so I am looping on ion-item using ngFor to return a list of message comming from a Json : *ngFor="let notification of feed.getNotifications()" (click)="openImportantMsg(i)" . 根据ionic项目,我显示一个列表,所以我使用ngFor循环显示ion-item以返回来自Json的消息列表: *ngFor="let notification of feed.getNotifications()" (click)="openImportantMsg(i)"

According to that list of item (who's part of another ionic page), when I click on an item I display the same message in a modal (the modal is another page as well), actually it almost works but I am returning the whole array of item in my modal call important-msg and I need only the selected one to display. 根据该项目的列表(属于另一个离子页面的一部分),当我单击某个项目时,我在模式中显示相同的消息(模式也是另一个页面), 实际上它几乎可以工作,但是我将返回整个数组模态调用Important-msg中的项,我只需要显示所选项即可。

The idea is to retrive the selected item in the modal (important-msg) maybe only css way is the best / easy way to make it? 这个想法是在模态(important-msg)中检索选定的项目,也许只有CSS方式才是最好/简单的方法?

Thanks in advance and feel free to ask any question I stay around. 在此先感谢您,随时问我任何问题。

Here is my actual code including a function binding method who's really great to use: 这是我的实际代码,其中包括一个非常有用的函数绑定方法:

app.html: app.html:

<div>
    <h2>Notifications</h2>
    <ion-item no-lines text-wrap *ngFor="let notification of 
    feed.getNotifications()" (click)="openImportantMsg(i)">
    <ion-icon name="notifications" color="primary" item-start></ion-icon>
        {{ notification.message }}
    </ion-item>
</div>

app.ts: 应用程式:

openImportantMsg(message, i): void {
    this.importantMsgCtrl.show(message);
    this.importantMsgCtrl.customeNotif(i);
}

important-msg-controller.ts: Important-msg-controller.ts:

import { Injectable } from '@angular/core';

@Injectable()
export class ImportantMsgController {
    message: any;

    constructor() {}

    show(message: string): void {}

    hide(): void {}

    customeNotif(message): void {}
}

important-msg.html: Important-msg.html:

<ion-item no-lines text-wrap *ngFor="let notification of feed.getNotifications(); let isOdd = odd; let i = index;">
    <div *ngIf="i == isOdd"> {{notification.message}}</div>
    <p>{{isEven}} here come isEven</p>
    <p>{{i}}Here comes index</p>
</ion-item>

important-msg.ts: Important-msg.ts:

export class ImportantMsgComponent {
    active: boolean = false;
    message: string;
    feed: Feed = new Feed();

    constructor(
        private importantMsgCtrl: ImportantMsgController,
        public feedService: FeedService
    ) {
            this.importantMsgCtrl.show = this.show.bind(this);
            this.importantMsgCtrl.hide = this.hide.bind(this);
            this.importantMsgCtrl.customeNotif = this.customNotif.bind(this);
            console.log('Hello ImportantMsgComponent Component');

            this.feedService.feedAsObs.subscribe(feed => {
                if (feed) {
                    this.feed = feed;
                }
            });
        }

show(message: string): void {
    this.active = true;
    this.message = message;
}

hide(): void {
    if (this.active) {
        this.active = false;
    }
}

With this one I tried to flag the selected element giving him a id 通过这个,我试图标记所选元素并为其指定一个ID

customNotif(message: any) {
    let i = [];
    for (message = 1; message < 100; message++) {
        console.log(message, 'here is message value');
    }
    console.log(i, 'here is i value !');
    return i;
}

Finally I found it and it was pretty simple: 终于我找到了,它非常简单:

app.html: app.html:

      <ion-item no-lines text-wrap *ngFor="let notification of 
    feed.getNotifications()" 
   (click)="openImportantMsg(notification.message)">
        <ion-icon name="notifications" color="primary" item-start></ion-icon>
        {{ notification.message }}
      </ion-item>

app.ts: 应用程式:

  openImportantMsg(message): void {
    this.importantMsgCtrl.show(message);
   }

important-msg.html: Important-msg.html:

 <p>{{message}}</p>

PS: And I delete all the other code in important-msg.ts and important-msg.controller.ts PS:然后我删除了重要的msg.ts和重要的msg.controller.ts中的所有其他代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM