我試圖從URL無法從路徑URL
@Component({
templateUrl: './confirm-registration.component.html',
})
export class ConfirmRegistrationComponent implements OnInit {
constructor(private route: ActivatedRoute,
private router: Router) { }
ngOnInit() {
this.route.params.switchMap((params: Params) => {
return console.log('token:', params['registrationToken']);
});
}
}
創建我的角CLI項目,負載參數的簡單組件讀取PARAMS,但我得到的錯誤:
無法編譯。
.../confirm-registration.component.ts (15,33): Argument of type '(params: Params) => void' is not assignable to parameter of type '(value: Params, index: number) => ObservableInput<{}>'. Type 'void' is not assignable to type 'ObservableInput<{}>'.
我在4.0.3版本中使用Angular。我犯了什麼錯誤?
你可以試試這個的console.log(this.route.snapshot.params [「registrationToken」]) –
什麼是你的路線,可在req.query –
你正在使用switchMap,它應該返回一個Observable,但你返回調用'console.log'的結果(在這種情況下:void)。請使用'do'操作程序登錄到控制檯進行調試: – dzejdzej