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
import { Injectable } from '@angular/core'; | |
import { Router, NavigationStart } from '@angular/router'; | |
import { Observable } from 'rxjs'; | |
import { Subject } from 'rxjs/Subject'; | |
import { Alert, AlertType } from '../models/alert'; | |
@Injectable() | |
export class AlertService { | |
private subject = new Subject<Alert>(); |
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
getResultFromRemote(): Subject<string> { | |
const subs = new Subject<string>(); | |
this.http.get('http://localhost/service') | |
.subscribe((res) => { | |
subs.next(res); | |
}, (err) => { | |
subs.error(res); | |
}); | |
return subs; | |
} |
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
... | |
import * as data from './example.json'; | |
... | |
const word = (<any>data).name; | |
console.log(word); // output 'testing' |
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 cloned = JSON.parse(JSON.stringify(original)); |
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
returnObservable(): Observable<any> { | |
return new Observable(observer => { | |
if (/* whatever */) { | |
return observer.next(body.data); | |
} else { | |
return observer.error(body.data); | |
} | |
return { unsubscribe() {} }; | |
}); |
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
requestName(): Observable<Call> { | |
return new Observable(observer => { | |
const endpoint = 'endpoint'; | |
const data = {}; | |
// #region:multipart | |
// In case of multipart | |
const formData: FormData = new FormData(); | |
Object.keys(data).forEach((key) => { | |
formData.append(key, data[key]); |
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
import { ActivatedRoute, Router, NavigationExtras } from '@angular/router'; | |
... | |
const extras: NavigationExtras = { | |
relativeTo: this.route, | |
queryParams: { name: value }, | |
queryParamsHandling: 'merge' | |
}; | |
this.router.navigate([], extras).then(() => { /* continue here */ }); |
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
// Function with a promise | |
const doAsyncStuff = () => { | |
return new Promise((resolve, reject) => { | |
if (stuff) { | |
resolve('cool'); | |
} | |
reject('bad'); | |
}); | |
}; |
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
import 'dart:math' as math; | |
import 'package:flutter/foundation.dart'; | |
import 'package:flutter/rendering.dart'; | |
import 'package:flutter/widgets.dart'; | |
/// Signature for a function that creates a [TileSize] for a given index. | |
typedef TileSize IndexedTileSizeBuilder(int index); | |
/// Creates grid layouts with a fixed number of spans in the cross axis. |
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
// More info on locales and codes for names on MDN 'toLocaleString' | |
weekdaysArray(locale = 'en-us', startMonday = false) { | |
const initYear = 2006; // Year that started on the first day of week | |
return Array.from({ length: 7 }, (v, k) => k) | |
.map(weekday => new Date(initYear, 0, weekday + (startMonday ? 1 : 0) + 1) | |
.toLocaleString(locale, { weekday: 'narrow' })); | |
} |