function validateInSequence(
...validators: ( (formControl: FormControl) => any )[]
): (formControl: FormControl) => any {
return function (formControl: FormControl): any {
for (let i = 0; i < validators.length; i++) {
const validationResult = validators[i](formControl);
if (validationResult !== null) {
return validationResult;
}
}
return null;
};
}
new FormControl('', [validateInSequence(Validators.required, Validators.email)]);
<a [routerLink]="..." [queryParams]="{category: item}" ... > ... </a>
let declarations = [SomeComponent];
if (!environment.production) {
const devDeclarations = [/*ваши дев компоненты*/];
declarations = declarations.concat(devDeclarations); // равносильно [...declarations, ...devDeclarations]
}
@NgModule({
declarations,
/*...*/
})
export class SomeModuleClass {}
window.open('https://google.com', null, 'menubar=off,toolbar=off')
function someFunction<T>(): T {
return new T();
}
return this.http
.get<Person>("http://test/api/v1/person/view", config)
.map(p => new Person(p));
class SomeComponent {
private _isBlocked$$: Subject<boolean> = new Subject();
public isBlocked$: Observable<boolean> = this._isBlocked$$.asObservable();
public ngOnInit(): void {
this.isBlocked$
.switchMap((isBlocked: boolean) =>
isBlocked ? this.http.post(apiPath) : Observable.of(null))
.subscribe((data: Array<any>) => {
if (data !== null) {
this.notise = this.mapData(data);
}
});
}
public someMethod(bool: boolean): void {
this._isBlocked$$.next(bool);
}
}
Observable.timer(0, 2000).takeUntil(this.isBlocked$)
private ngUnsubscribe: Subject<void> = new Subject<void>();
, cледовательно ничего кроме "пустого" значения передать в .next() компилятор тайпскрипта и не разрешит.The Observer callback to receive a valueless notification of type complete from the Observable. Notifies the Observer that the Observable has finished sending push-based notifications.
private _activatedRoute: ActivatedRoute
и private _router: Router
this._activatedRoute.paramMap.subscribe((params: ParamMap) => {
let date: string = params.get('date');
if (/*если дата неправильна*/) {
date = ...; // изменим дату на корректную
this._router.navigate(['/date', date]);
}
})