I'm new to Angular Js.
Below is a simple bank application, user can register,login the application. After successful login user can deposit ,withdraw cash and view his transaction history.
Register and Login is working. Deposit not working showing below error
Showing server error in browser as POST http://localhost:3000/deposit 422 (Unprocessable Entity)
data.services.ts file
const options={
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
}
//deposit API
deposit(acno:any,pswd:any,amnt:any){
const data={
acno,
pswd,
amnt
}
//deposit api
return this.http.post("http://localhost:3000/deposit",data,this.getOption())
}
//get options in httpheaders
getOption(){
const token = JSON.parse(localStorage.getItem("token")||'')
let headers = new HttpHeaders({ 'Content-Type': 'application/json' })
if(token){
headers = headers.append('x-access-token',token)
options.headers = headers
}
return options
}
deposit components.ts file
deposit(){
var acno=this.depositForm.value.acno
var pswd=this.depositForm.value.pswd
var amnt=this.depositForm.value.amnt
if(this.depositForm.valid){
var result= this.ds.deposit(acno,pswd,amnt)
.subscribe((result:any)=>{
if(result){
alert(result.message);
}
},
(result)=>{
alert(result.message)
}
)
}
I'm new to Angular Js. Below is a simple bank application, user can register,login the application. After successful login user can deposit ,withdraw cash and view his transaction history. Register and Login is working. Deposit not working showing below error Showing server error in browser as POST http://localhost:3000/deposit 422 (Unprocessable Entity)
data.services.ts file
const options={ headers: new HttpHeaders({ 'Content-Type': 'application/json' }) } //deposit API deposit(acno:any,pswd:any,amnt:any){ const data={ acno, pswd, amnt }
}
//get options in httpheaders getOption(){ const token = JSON.parse(localStorage.getItem("token")||'')
}
deposit components.ts file
deposit(){
}