Created
July 17, 2019 09:11
-
-
Save onejohi/08391cec0077c5cce3083d015e09504e to your computer and use it in GitHub Desktop.
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 StateService from '../services/state.service.ts'; | |
@Component({ | |
selector: 'app-change-state', | |
template: ` | |
<div> | |
<div> {{username }} </div> | |
<input [(ngModel)]="username" placeholder="enter username" /> | |
<button (click)="updateUsername()"></button> | |
</div> | |
`, | |
}) | |
export class ChangeState implements OnInit { | |
username: string; | |
constructor(private state: StateService) { } | |
ngOnInit() { | |
this.state.username.subscribe(result => { | |
this.username = result; // this set's the username to the default observable value | |
}); | |
} | |
updateUsername() { | |
this.state.changeUsername(this.username); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment