Мне нужен этот формат URL:
http://localhost:8089/api/Logins/CheckPassword?ID=[UserID]&Password=[Password]
Мой код не работает:
loginComponent.ts
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Observable } from 'rxjs';
import { LoginService } from '../login.service';
import { Login } from '../login';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
loginForm: FormGroup;
loading=false;
submitted=false;
url: string;
constructor(
private formbuilder: FormBuilder,
private loginService: LoginService,
private router:Router,
private route: ActivatedRoute
) {
if(this.loginService.getLoginById)
{
this.router.navigate(['/']);
}
}
ngOnInit() {
this.loginForm = this.formbuilder.group({
Id: ['', [Validators.required]],
password: ['',Validators.required]
});
}
get f()
{
return this.loginForm.controls;
}
onFormSubmit() {
this.submitted=true;
if(this.loginForm.invalid)
{
return;
}
this.loading=true;
this.loginService.getLoginById()
//.pipe(first())
.subscribe(
data =>{
this.router.navigate([this.url]);
},
error =>
{
this.loading=false;
});
}
}
loginService.ts
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Login } from './login';
@Injectable({
providedIn: 'root'
})
export class LoginService {
constructor(private http: HttpClient) { }
getLoginById(): Observable<any>{
const _params=new HttpParams();
_params: _params.set('ID=','UserID');
_params: _params.set('Password=','Password');
return
this.http.get('http://localhost:8089/api/Logins/CheckPassword?',
{
params:_params
});
console.log(_params);
}
}