Created
April 12, 2017 10:20
-
-
Save navix/c9a12ce35804bcf24ff8c8e3ff786938 to your computer and use it in GitHub Desktop.
Angular: input/output decorators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div *ngFor="let person of persons"> | |
| <app-person [data]="person" (upVote)="upVote(person, $event)"></app-person> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component, OnInit } from '@angular/core'; | |
| import { DataService } from './data.service'; | |
| @Component({ | |
| selector: 'app-root', | |
| templateUrl: './app.component.html', | |
| styleUrls: ['./app.component.css'] | |
| }) | |
| export class AppComponent implements OnInit { | |
| title = 'app works!!!'; | |
| persons; | |
| constructor(private dataService: DataService) { | |
| } | |
| ngOnInit() { | |
| this.persons = this.dataService.getPersons(); | |
| } | |
| upVote(person, inc) { | |
| person.points += inc; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Person! {{ data.name }}: {{ data.points }} | |
| <button (click)="upVoteClick(1)">Up Vote!</button> | |
| <button (click)="upVoteClick(10)">Up Vote +10!</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; | |
| @Component({ | |
| selector: 'app-person', | |
| templateUrl: './person.component.html', | |
| styleUrls: ['./person.component.css'] | |
| }) | |
| export class PersonComponent implements OnInit { | |
| @Input() data; | |
| @Output() upVote = new EventEmitter(); | |
| constructor() { } | |
| ngOnInit() { | |
| } | |
| upVoteClick(inc) { | |
| this.upVote.emit(inc); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment