Skip to content

feat(img): add ionError event - #17134

Merged
liamdebeasi merged 7 commits into
ionic-team:masterfrom
pickfire:master
Mar 27, 2019
Merged

liamdebeasi merged 7 commits into
ionic-team:masterfrom
pickfire:master

Conversation

@pickfire

Copy link
Copy Markdown
Contributor

closes #16947

Short description of what this resolves:

Propagate ionError event for img

Changes proposed in this pull request:

Ionic Version: 4.6.0

Fixes: #16947

@ionitron-bot ionitron-bot Bot added package: angular @ionic/angular package package: core @ionic/core package labels Jan 16, 2019
src={this.loadSrc}
alt={this.alt}
decoding="async"
onError={this.loadError}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering why we can't just use onError directly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That error trigger even before the image start loading as there is no src.

@paulstelzer paulstelzer Jan 17, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pickfire I think manu means removing onError={this.loadError} and instead using the Listen decorator:

@Listen('error')
onImgError(ev: Event) {
 // Your code from loadError
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested that but it does not seem to work.

  /** Emitted when img failed to load */
  @Event() ionError!: EventEmitter<void>;

  @Listen('error')
  onImgError() {
    this.ionError.emit();
  }
  ...
  render() {
    return (
      <img
        src={this.loadSrc}
        alt={this.alt}
        decoding="async"
        // onError={this.loadError}
      />
    );
  }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SamVerschueren

Copy link
Copy Markdown

Can this PR be merged? It's really blocking us because we can't implement a fallback image when image loading fails. I just want to know if I should put effort in migrating everything to a regular img tag or if I can wait until this is merged and released.

@pickfire

Copy link
Copy Markdown
Contributor Author

@SamVerschueren Same, it's blocking for us as well.

I am not sure whether this PR has been merged yet though, Ionic pull requests are weird.

@liamdebeasi liamdebeasi left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a few small changes, and we'll be good to go.

Comment thread core/src/components/img/img.tsx Resolved
Comment thread core/src/components/img/img.tsx Resolved
src={this.loadSrc}
alt={this.alt}
decoding="async"
onError={this.loadError}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liamdebeasi liamdebeasi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! 👍

@liamdebeasi liamdebeasi left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the work! 🎉

edit: not sure why I re-approved... but I did!

@liamdebeasi
liamdebeasi merged commit 04f931f into ionic-team:master Mar 27, 2019
@pickfire

Copy link
Copy Markdown
Contributor Author

@liamdebeasi Thanks a lot for merging this. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: angular @ionic/angular package package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ion-img onerror

5 participants