Skip to content

Instantly share code, notes, and snippets.

View ssougnez's full-sized avatar

Sébastien Sougnez ssougnez

View GitHub Profile
interval(1000)
.pipe(
takeUntil(this.destroy$),
map(() => this._http.put('http://localhost:3000/documents/1', { lastUpdate: new Date() }).subscribe())
)
.subscribe(x => console.log(x));
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { interval } from 'rxjs';
import { map, takeUntil } from 'rxjs/operators';
import { BaseComponent } from './base-component';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
{
"documents": [
{
"id": "1",
"lastUpdate": null
}
]
}
import { interval, Observable } from 'rxjs';
import { take } from 'rxjs/operators';
const observable$: Observable<number> = interval(1000);
observable$
.pipe(
take(1)
)
.subscribe(x => console.log(x));
<ng-container *ngIf="data$ | async as user; else loading">
<div>First name: {{ user.firstName }}</div>
<div>Last name: {{ user.lastName }}</div>
<div>Age name: {{ user.age | number }}</div>
</ng-container>
<ng-template #loading>Loading...</ng-template>
<ng-container *ngIf="data$ | async as user">
<div>First name: {{ user.firstName }}</div>
<div>Last name: {{ user.lastName }}</div>
<div>Age name: {{ user.age | number }}</div>
</ng-container>
<div>First name: {{ (data$ | async).firstName }}</div>
<div>Last name: {{ (data$ | async).lastName }}</div>
<div>Age name: {{ ((data$ | async).age) | number }}</div>
import { Component, Input } from '@angular/core';
import { Observable } from 'rxjs';
@Component({
selector: 'app-user',
templateUrl: './user.component.html',
styleUrls: ['./user.component.scss']
})
export class UserComponent {
import { Component, Input, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
@Component({
selector: 'app-user',
templateUrl: './user.component.html',
styleUrls: ['./user.component.scss']
})
export class UserComponent implements OnInit {