<legend id='gmLHG'><style id='gmLHG'><dir id='gmLHG'><q id='gmLHG'></q></dir></style></legend>

          <bdo id='gmLHG'></bdo><ul id='gmLHG'></ul>
      1. <tfoot id='gmLHG'></tfoot>
        <i id='gmLHG'><tr id='gmLHG'><dt id='gmLHG'><q id='gmLHG'><span id='gmLHG'><b id='gmLHG'><form id='gmLHG'><ins id='gmLHG'></ins><ul id='gmLHG'></ul><sub id='gmLHG'></sub></form><legend id='gmLHG'></legend><bdo id='gmLHG'><pre id='gmLHG'><center id='gmLHG'></center></pre></bdo></b><th id='gmLHG'></th></span></q></dt></tr></i><div id='gmLHG'><tfoot id='gmLHG'></tfoot><dl id='gmLHG'><fieldset id='gmLHG'></fieldset></dl></div>

      2. <small id='gmLHG'></small><noframes id='gmLHG'>

      3. 如何更新 ionic 2 侧菜单中的值

        时间:2023-09-08

          1. <legend id='1NmM4'><style id='1NmM4'><dir id='1NmM4'><q id='1NmM4'></q></dir></style></legend>
              <bdo id='1NmM4'></bdo><ul id='1NmM4'></ul>

            • <small id='1NmM4'></small><noframes id='1NmM4'>

              <i id='1NmM4'><tr id='1NmM4'><dt id='1NmM4'><q id='1NmM4'><span id='1NmM4'><b id='1NmM4'><form id='1NmM4'><ins id='1NmM4'></ins><ul id='1NmM4'></ul><sub id='1NmM4'></sub></form><legend id='1NmM4'></legend><bdo id='1NmM4'><pre id='1NmM4'><center id='1NmM4'></center></pre></bdo></b><th id='1NmM4'></th></span></q></dt></tr></i><div id='1NmM4'><tfoot id='1NmM4'></tfoot><dl id='1NmM4'><fieldset id='1NmM4'></fieldset></dl></div>
              <tfoot id='1NmM4'></tfoot>
                <tbody id='1NmM4'></tbody>

                • 本文介绍了如何更新 ionic 2 侧菜单中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何将日期从页面转移"到 Ionic2 中的 side-menu,即 -具有 app.page.html 如下:

                  How to "transfer" date from page into side-menu in Ionic2, i.e - Having app.page.html like following:

                  <ion-menu [content]="content">
                  
                      <ion-content class="menu-left">
                          <!-- User profile -->
                          <div text-center padding-top padding-bottom class="primary-bg menu-left">
                              <a menuClose>
                                  <h4 light>{{userName}}</h4>
                              </a>
                          </div>
                  
                          <ion-list class="list-full-border">
                              <button ion-item menuClose *ngFor="let page of pages" (click)="openPage(page)">
                          <ion-icon item-left name="{{ page.icon }}"></ion-icon>
                          {{ page.title }}
                          <ion-badge color="danger" item-right *ngIf="page.count">{{ page.count }}</ion-badge>
                        </button>
                          </ion-list>
                      </ion-content>
                  
                  </ion-menu>
                  
                  <ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
                  

                  如何根据从 facebookLogin.page 获取的数据在页面中的操作上更新 userName 值?

                  how to update userName value upon the action in the page upon the data gotten from facebookLogin.page ?

                  facebookLogin.page.ts:

                  ...
                  fbLogin() {
                      Facebook.login(["public_profile", "email"])
                        .then((resp: FacebookLoginResponse) => {
                  
                          if (resp.status === "connected") {
                            Facebook.api("/me", ["public_profile", "email"])
                              .then(res => {
                               this.userName = res.name
                                this.login({name: this.userName})
                              })
                          ...
                        );
                    }
                  
                   login(params) {
                      this.nav.setRoot(HomePage, params);
                    }
                  ...
                  

                  (那么,我如何将使用 facebook 登录后获得的 userName 导入 app.html 中的 ion-sideMenu 中;如何我可以让 EventEmmiterservice/observe 来观察 app.html 的 ion-menu 的变化……其他方式?)

                  (so, how would I import the userName which I get after login with facebook into ion-sideMenu in app.html; how I could make EventEmmiter, service/observe for changes in app.html's ion-menu ... some other way?)

                  推荐答案

                  ionic2 - 使用事件

                  查看活动文档

                  它们允许您从任何页面发布"操作,并在另一个页面中订阅它以检索值.你的场景看起来有点像这样.

                  They allow you to 'publish' an action from any page, and subscribe to it in another page to retrieve the value. Your scenario would look a bit like this.

                  导入(在 Facebooklogin.componentapp.component 上)

                  Import (both on Facebooklogin.component and app.component)

                  import { Events } from 'ionic-angular'; 和你的构造函数 constructor(public events: Events)

                  然后,每当您更改 userName(例如在 facebook 登录的处理程序中)时,都会像这样发布值.

                  Then, whenever you change your userName (f.e. in the handler of the facebook login) publish the value like this.

                  fbLogin() {
                      Facebook.login(["public_profile", "email"])
                        .then((resp: FacebookLoginResponse) => {
                  
                          if (resp.status === "connected") {
                            Facebook.api("/me", ["public_profile", "email"])
                              .then(res => {
                               this.userName = res.name
                               // publish the username change to the events
                               this.events.publish('username:changed', this.userName);
                                this.login({name: this.userName})
                              })
                          //...
                        );
                    }
                  

                  并订阅在您的 app.component 中进行的任何发布

                  And subscribe to any publishes being made in your app.component

                  userName: string;
                  
                  constructor(events: Events) {
                     this.userName = "not logged in";
                  
                     events.subscribe('username:changed', username => {
                        if(username !== undefined && username !== ""){
                          this.userName = username;
                        }
                     }) //... 
                  }
                  

                  <小时>

                  angular2 - 使用 EventEmitter


                  angular2 - using EventEmitter

                  import { EventEmitter } from '@angular/core';
                  
                  public userChanged = new EventEmitter();
                  
                  fbLogin() {
                          Facebook.login(["public_profile", "email"])
                            .then((resp: FacebookLoginResponse) => {
                  
                              if (resp.status === "connected") {
                                Facebook.api("/me", ["public_profile", "email"])
                                  .then(res => {
                                   this.userName = res.name
                                   // publish the username change to the events
                                   this.userChanged.emit(this.userName);
                                   this.login({name: this.userName})
                                  })
                              ...
                            );
                        }
                  

                  App.component

                  App.component

                  import { FacebookLogin } from '../pages/facebook/facebook.component';
                  
                  public userName;
                  
                  constructor(fb: FacebookLogin){
                  
                      this.userName = "";
                      //subscribe to the page's EventEmitter
                      this.fb.userChanged.subscribe(username => {
                         this.userName = username;
                      });
                  }
                  

                  或使用 EventEmitter 作为 Output,如本 S.O. 中所述.回答:EventEmitter 的正确用法是什么?

                  OR use the EventEmitter as an Output as described in this S.O. answer: What is the proper use of an EventEmitter?

                  这篇关于如何更新 ionic 2 侧菜单中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在角度2中动态更改css类名 下一篇:在 ionic 2 应用程序中打开 PDF 文件

                  相关文章

                  最新文章

                    <i id='W7gRt'><tr id='W7gRt'><dt id='W7gRt'><q id='W7gRt'><span id='W7gRt'><b id='W7gRt'><form id='W7gRt'><ins id='W7gRt'></ins><ul id='W7gRt'></ul><sub id='W7gRt'></sub></form><legend id='W7gRt'></legend><bdo id='W7gRt'><pre id='W7gRt'><center id='W7gRt'></center></pre></bdo></b><th id='W7gRt'></th></span></q></dt></tr></i><div id='W7gRt'><tfoot id='W7gRt'></tfoot><dl id='W7gRt'><fieldset id='W7gRt'></fieldset></dl></div>
                    • <bdo id='W7gRt'></bdo><ul id='W7gRt'></ul>
                  1. <small id='W7gRt'></small><noframes id='W7gRt'>

                  2. <tfoot id='W7gRt'></tfoot>

                  3. <legend id='W7gRt'><style id='W7gRt'><dir id='W7gRt'><q id='W7gRt'></q></dir></style></legend>