Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ionViewDidLoad() not working in Modal #8414

Closed
dhndeveloper opened this issue Oct 3, 2016 · 11 comments · Fixed by #8624
Closed

ionViewDidLoad() not working in Modal #8414

dhndeveloper opened this issue Oct 3, 2016 · 11 comments · Fixed by #8624
Assignees

Comments

@dhndeveloper
Copy link

dhndeveloper commented Oct 3, 2016

Note: If you are having problems formatting your issue please refer to this article on using markdown in Github:

https://guides.github.com/features/mastering-markdown/

Note: for support questions, please use one of these channels:

https://forum.ionicframework.com/
http://ionicworldwide.herokuapp.com/

Short description of the problem:

ionViewDidLoad() not executing in Modal

What behavior are you expecting?

I'm expecting a log from the Push Page 'Hello Push Page'

Steps to reproduce:

  1. Generated a blank app
  2. Modified home page to:
import { Component } from '@angular/core';

import { NavController, ModalController } from 'ionic-angular';

import { Push } from '../push/push';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController, public modalCtrl: ModalController) {

let createModal = this.modalCtrl.create(Push);

createModal.onDidDismiss( data => {

});

createModal.present(createModal);

  }

}
  1. Push Page:

`
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

/*
  Generated class for the Push page.

  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/
@Component({
  selector: 'page-push',
  templateUrl: 'push.html'
})
export class Push {

  constructor(public navCtrl: NavController) {}

  ionViewDidLoad() {
    console.log('Hello Push Page');
  }

}

`

insert any relevant code between the above and below backticks

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)

Which Ionic Version? 1.x or 2.x

Ionic Framework Version: 2.0.0-rc.0

Plunker that shows an example of your issue

Run ionic info from terminal/cmd prompt: (paste output below)

Cordova CLI: 6.3.1
Ionic Framework Version: 2.0.0-rc.0
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.1.0-beta.1
ios-deploy version: 1.9.0
ios-sim version: Not installed
OS: Mac OS X El Capitan
Node Version: v6.7.0
Xcode version: Xcode 8.0 Build version 8A218a

@comfortme
Copy link

same issue here.

@fastf0rward
Copy link

+1

@perdjurner
Copy link
Contributor

I have the same problem.

As a work-around until this is fixed I put my setup logic for the modal in the constructor instead.

@jgw96 jgw96 added the v2 label Oct 3, 2016
@baltazaroliveira
Copy link

+1

@jgw96
Copy link
Contributor

jgw96 commented Oct 4, 2016

Hello all, i am going to close this issue as a duplicate of #8449. Thanks for using Ionic!

@jgw96 jgw96 closed this as completed Oct 4, 2016
@aggiustino
Copy link

+1

@manucorporat
Copy link
Contributor

@jgw96 I don't think it is the same issue. this issue is about ionViewDidLoad not being called at all.

@manucorporat manucorporat reopened this Oct 4, 2016
@mattroth
Copy link

mattroth commented Oct 5, 2016

Here is my work around:

Function to Create Modal


addFamilyMemberTapped() {
    let data = {initFormHack: true};
    let modal = this.modalCtrl.create(Profile, data);
    modal.onDidDismiss(data => {
      if (data.activeMember) {
        console.log("modal dismissed...");
      }
    });

    modal.present();
  }

Page Loaded in Modal


  constructor(private navParams: NavParams) {
    /**
     * HACK FOR BUG: https://github.com/driftyco/ionic/issues/8414
     */
    if (navParams.data['initFormHack']) {
      this.ionViewDidLoad();
    }
  }

@dhndeveloper
Copy link
Author

dhndeveloper commented Oct 6, 2016

@mattroth that work around didn't work for me.... I need to access nativeElement from a @ViewChild so my guess is that the elements are loaded yet when the constructor is fired

Example:

@ViewChild('autocompleteStart') autoCompleteStart;
@ViewChild('autocompleteEnd') autoCompleteEnd;

ionViewDidLoad(): void {
this.autocomplete.loadAutoCompleteScript(this.autoCompleteStart.nativeElement, this.autoCompleteEnd.nativeElement);
}

I'm using the Autocomplete Google API.

Actually just figured out this workaround:

<div (click)="ionViewDidLoad()" class="autocomplete">
  <ion-label primary stacked> Address? </ion-label>
  <input #autocomplete class="autocompleteInput" type="text" placeholder="100 Earth Circle" [(ngModel)]="address" />
</div>

@baltazaroliveira
Copy link

My "workaround" is simple! :-) i have create a function and insert inside the constructor. Problem Solved!
When this issue is resolved i change the name of function to ionViewDidLoad.

@BlackFoks
Copy link

I found that ionViewDidEnter works in modals so I added a workaround on top of it:

  ionViewLoaded = false;
  ionViewDidEnter() {
    if (!this.ionViewLoaded) {
      this.ionViewLoaded = true;
      this.ionViewDidLoad();
    }
  }

Hope this will help someone.

@manucorporat manucorporat self-assigned this Oct 6, 2016
manucorporat added a commit to manucorporat/ionic that referenced this issue Oct 10, 2016
manucorporat added a commit to manucorporat/ionic that referenced this issue Oct 10, 2016
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants