Skip to content

Instantly share code, notes, and snippets.

View nitayneeman's full-sized avatar

Nitay Neeman nitayneeman

View GitHub Profile
@Injectable()
export class AppService {
fetchData(): Rx.Observable<string> {
return Rx.Observable
.of('Todo')
.delay(1000);
}
}
@Component({
selector: 'my-app',
templateUrl: './app.component.html'
})
export class AppComponent {
public todos: string[];
constructor(private appService: AppService) {
this.todos = ['Todo', 'Todo', 'Todo'];
}
<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>
@Directive({
selector: '[domChange]'
})
export class DomChangeDirective {
private changes: MutationObserver;
@Output()
public domChange = new EventEmitter();
constructor(private elementRef: ElementRef) {
ngOnDestroy(): void {
this.changes.disconnect();
}
export class DomChangeDirective implements OnDestroy {
<ul (domChange)="onDomChange($event)">
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
observer.disconnect();
Rx.Observable
.interval(1000)
.first((value) => value === 3)
.subscribe(
(value) => console.log(`Emitted value: ${value}`),
(error) => console.error(error),
() => console.log('Completed')
);