Skip to content

Should only fire output property once even if both in [outputs] and decorated w/ @Output #4798

Closed

Description

@wardbell

Consider this component:

@Component({
  selector: 'hero-detail',
  inputs: ['hero'],
  outputs: ['deleted'],
  template: `
    <div>
      <b>Hero Detail: {{hero?.fullName}}</b>
      <button (click)="onDelete()">Delete</button>
    </div>
  `
})
class HeroDetailComponent {

  @Input()
  hero: Hero;

  @Output()
  deleted = new EventEmitter();

  onDelete() {
    this.deleted.next(this.hero);
  }
}

Now we bind to it:

<hero-detail [hero]="currentHero" (deleted)="onDeleted($event)"></hero-detail>

When the user clicks the Delete button inside <hero-detail>, the parent's onDeleted method is called twice.

Remove either the [outputs] array or the @Output decoration and the parent's method is called only once.

The number of parent method calls increase by one for each additional @Output decoration.

I maintain that any number of mentions as an output > 1 should still mean a single call to the parent method.

Activity

  1. changed the title [-]Should only fire output property once even when list both in [outputs] and w/ @Output[/-] [+]Should only fire output property once even if both in [outputs] and decorated w/ @Output[/+] on Oct 16, 2015
  2. ericmartinezr commented on Oct 17, 2015

    @ericmartinezr
    Contributor

    FWIW this was reported a few days ago, but it was closed immediatly #4611

  3. jessegood commented on Oct 17, 2015

    @jessegood

    Is there a use case for having both? I would consider this a mistake in the code and would like the framework to tell me by throwing an exception.

  4. mhevery commented on Oct 22, 2015

    @mhevery
    Contributor

    I think we should throw an error when the same event is registered more then once.

  5. wardbell commented on Oct 24, 2015

    @wardbell
    ContributorAuthor

    That's ok too. I'm more of a "be tolerant in what you accept person" myself but that policy can lead us into trouble and maybe it would here. Lets do something😊

  6. angular-automatic-lock-bot commented on Sep 7, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  7. locked and limited conversation to collaborators on Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions