What's the change in the second angular?



  • What an event changeunder what conditions does it occur and how can it be used?
    That's what I signed into the next example through. (change)="update()"?

    http://plnkr.co/edit/mfoToOSLU6IU2zr0A8OB?p=preview

    import {Component, View, Input, Output, EventEmitter, OnChanges} from '@angular/core'
    

    @Component({
    selector: 'inner-component',
    template: <label><input type="checkbox" [(ngModel)]="data.isSelected"> Selected</label>
    })
    export class InnerComponent {
    data = { isSelected: false };
    }

    @Component({
    selector: 'my-app',
    template: <p><inner-component (change)="update()"></inner-component></p> <p>The component was updated {{count}} times</p> ,
    directives: [InnerComponent]
    })
    export class AppComponent {
    count = 0;

    update() {
    ++this.count;
    }
    }

    PS: //stackoverflow.com/q/38227838/4928642



  • This is an outbreak of events: change It's happening in the interior, but it's going up where it's being processed by an external component. It can be checked if the event is removed:

    http://plnkr.co/edit/J8pRg3ow41PAqdMteKwg?p=preview

    @Component({
      selector: 'my-app',
      template: `
        <p><inner-component (change)="update($event)"></inner-component></p>
        <p>The component was updated {{count}} times</p>
      `,
      directives: [InnerComponent]
    })
    export class AppComponent {
      count = 0;
    

    update($event) {
    console.log($event, $event.target, $event.currentTarget);
    ++this.count;
    }
    }


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2