Skip to content

Instantly share code, notes, and snippets.

@onejohi
Created July 17, 2019 09:11
Show Gist options
  • Save onejohi/08391cec0077c5cce3083d015e09504e to your computer and use it in GitHub Desktop.
Save onejohi/08391cec0077c5cce3083d015e09504e to your computer and use it in GitHub Desktop.
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