【出現的問題】 TS2339: property 'of' does not exist on type 'typeof Observable' git
【解決方法】(以下代碼粉色標記)github
import {AbstractControl, FormControl, FormGroup} from '@angular/forms'; import {of} from 'rxjs';
import {delay} from 'rxjs/operators'; export function mobileAsyncValidator (control: FormControl): any { var myreg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/; let valid = myreg.test(control.value); console.log('mobile的校驗結果是 - ' + valid); return of(valid ? null : {mobile: true}).pipe(
delay(1000)
);
}
【參考】app
(1) https://stackoverflow.com/questions/38067580/property-of-does-not-exist-on-type-typeof-observableide
(2) https://stackoverflow.com/questions/48826799/rxjs-observable-of-delay-is-not-a-function#answer-48826894ui
(3) https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.mdspa