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
@Injectable() | |
export class AppService { | |
fetchData(): Rx.Observable<string> { | |
return Rx.Observable | |
.of('Todo') | |
.delay(1000); | |
} | |
} |
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
@Component({ | |
selector: 'my-app', | |
templateUrl: './app.component.html' | |
}) | |
export class AppComponent { | |
public todos: string[]; | |
constructor(private appService: AppService) { | |
this.todos = ['Todo', 'Todo', 'Todo']; | |
} |
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
<ul> | |
<li *ngFor="let todo of todos; let i = index"> | |
{{ todo }} <button (click)="removeTodo(i)">Remove</button> | |
</li> | |
</ul> | |
<button (click)="addTodo()">Add Todo</button> |
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
@Directive({ | |
selector: '[domChange]' | |
}) | |
export class DomChangeDirective { | |
private changes: MutationObserver; | |
@Output() | |
public domChange = new EventEmitter(); | |
constructor(private elementRef: ElementRef) { |
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
ngOnDestroy(): void { | |
this.changes.disconnect(); | |
} |
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
export class DomChangeDirective implements OnDestroy { |
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
<ul (domChange)="onDomChange($event)"> |
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
const node = document.querySelector('.some-element'); | |
const observer = new MutationObserver((mutations) => { | |
mutations.forEach((mutation) => console.log(mutation)); | |
}); | |
observer.observe(node, { | |
attributes: true, | |
childList: true, | |
characterData: true |
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
observer.disconnect(); |
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
Rx.Observable | |
.interval(1000) | |
.first((value) => value === 3) | |
.subscribe( | |
(value) => console.log(`Emitted value: ${value}`), | |
(error) => console.error(error), | |
() => console.log('Completed') | |
); |
OlderNewer