Created
July 24, 2017 15:29
-
-
Save Deiru2k/a5d820732c52d782b0fe2f3996653e8d to your computer and use it in GitHub Desktop.
This file contains 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> | |
<input [(ngModel)]="value" /> | |
<button type="button" (click)="addValue(value)">Add</button> | |
</div> |
This file contains 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, Output, EventEmitter } from '@angular/core'; | |
@Component({ | |
selector: 'adder', | |
templateUrl: './template.html', | |
}) | |
export class AdderComponent { | |
value: String = ""; | |
@Output('onAdd') onAdd: EventEmitter<String> = new EventEmitter(); | |
addValue = (): void => { | |
this.onAdd.emit(this.value); | |
this.value = ""; | |
} | |
} |
This file contains 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> | |
<adder (onAdd)="addItem($event)"></adder> | |
<ul> | |
<li *ngFor="let item of items"> | |
{{item}} | |
</li> | |
<ul> | |
<div> |
This file contains 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 } from '@angular/core'; | |
@Component({ | |
selector: 'todo-list', | |
templateUrl: './TodoList.component.html', | |
styleUrls: ['./app.component.css'] | |
}) | |
export class TodoListComponent { | |
items: Array<String> = ['spam', 'eggs']; | |
addItem = (item: String): void => { | |
console.log(item); | |
this.items = [ ...this.items, item ]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment