Я пытаюсь создать приложение стека MEAN, и я не знаю, почему Angular не отправляет ни одного почтового запроса. Когда я пытаюсь отправить запрос, используя бессонницу, он работает нормально. Однако это не относится к angular. Плюс проблема заключается в функции LoginPlayer. Остальные в порядке. веб-сервис
import { Injectable } from '@angular/core';
import {HttpClient} from "@angular/common/http";
import Player from 'src/models/Player';
@Injectable({
providedIn: 'root'
})
export class WebService {
player:Player
readonly ROOT_URL;
constructor(private http:HttpClient) {
this.ROOT_URL='http://localhost:3000'
}
post(uri:string,payload:Player)
{
const obj={
FullName:payload.FullName,
Email:payload.Email,
Password:payload.Password,
Gender:payload.Gender,
}
return this.http.post(`${this.ROOT_URL}/${uri}`,obj);
}
LoginPlayer(uri:string,Email:String,Password:String)
{
const obj1={
Email:Email,
Password:Password
}
return this.http.post(`${this.ROOT_URL}/${uri}`,obj1);
}
get(uri:string){
return this.http.get(`${this.ROOT_URL}/${uri}`)
}
}
Player-Service
import { Injectable } from '@angular/core';
import { WebService } from './web.service';
import Player from 'src/models/Player';
@Injectable({
providedIn: 'root'
})
export class PlayerService {
Player:Player
constructor(private WebService:WebService) { }
createPlayer(player:Player){
return this.WebService.post(`Players`,player)
}
getPlayers()
{
return this.WebService.get('Players')
}
LoginPlayer(Email:String,Password:String){
return this.WebService.LoginPlayer(`players/Login`,Email,Password)
}
}
сервер. js
const express = require('express')
const app = express()
const header = require('body-parser')
const router = express.Router()
const player = require('./Players')
const mongoose = require('./dbConfig')
app.use(express.json())
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,POST,HEAD,OPTIONS,PUT,PATCH,DEL");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.listen(3000, () => console.log('Server started at 3000'))
app.post('/Players/Login', (req, res) => {
player.find({ Email: req.body.Email, Password: req.body.Password })
.then(player => console.log(player))
.catch((error) => console.log(error));
});
app.post('/Players', (req, res) => {
console.log(req.file);
(new player({ 'Name': req.body.Name, 'Email': req.body.Email, 'Password': req.body.Password, 'Gender': req.body.Gender, 'Sports': req.body.Sports }))
.save()
.then((player) => console.log(player))
.catch((error) => console.log(error))
});
app.patch('/Players/:Email', (req, res) => {
player.findOneAndUpdate({ Email: req.params.Email }, { $push: { Sports: req.body.Sports } })
.then(player => res.send(player))
.catch((error) => console.log(error));
});
app.get('/Players', (req, res) => {
player.find({})
.then(player => res.send(player))
.catch((error) => console.log(error));
});