mongodb未在.put角度函数上更新,未显示错误

时间:2018-09-23 05:27:27

标签: html node.js angular mongodb mongoose

我似乎不知道此代码出了什么问题,它在屏幕上显示了正确的答案,但是当我重新加载屏幕或检查数据库时,值未显示。

EVENTS.component.html

<div align="center">
  event list for check
  <table border='1'>
    <tr>
      <th> student code </th>
      <th> event code </th>
      <th> participation code </th>
      <th> event link </th>
      <th> verification </th>
    </tr>
    <tr *ngFor="let e of events">
      <td>{{e.cod_s}}</td>
      <td>{{e.cod_a}}</td>
      <td>{{e.cod_p}}</td>
      <td>{{e.link_e}}</td>
      <td bold>{{e.ver}}</td>
      <td><button (click)="rejectEvent(e._id)" type="submit">rejeitar</button></td>
      <td><button (click)="approveEvent(e._id)" type="submit">aprovar</button></td>
    </tr>
  </table>
</div>

EVENTS.js-放置函数

router.put('/:id', function(req, res, next) {
  Evento.findByIdAndUpdate(req.params.id, req.body, function(err, post) {
    if (err) return next(err);
    res.json(post);
  });
});

EVENTS.component.ts

export class AprovacaoEventosComponent implements OnInit {

  events: any;
  id = 0
  verifica = false;

  constructor(private route: ActivatedRoute,
    private http: HttpClient,
    private router: Router
  ) {}

  ngOnInit() {
    this.id = this.route.snapshot.params['id'];
    this.http.get("http://localhost:3000/EVENTS").subscribe(data => {
      this.eventos = dados;
    })
  }

  rejectEvent(id) {
    for (let i = 0; i < this.eventos.length; i++) {
      if (this.eventos[i]['_id'] == id) {
        var index = i;
      }
    }
    this.events[index]['verifica'] = false
    this.http.put('http://localhost:3000/EVENTS/' + id, this.events).subscribe(answer => {
      this.router.navigate(['/EVENT-APPROVAL'])
      console.log('rejected!')
    }, (erro) => {
      console.log("error")
    })
  }

  approveEvent(id) {
    for (let i = 0; i < this.eventos.length; i++) {
      if (this.events[i]['_id'] == id) {
        var index = i;
      }
    }
    this.eventos[index]['verifica'] = true
    this.http.put('http://localhost:3000/EVENTS/' + id, this.events).subscribe(resposta => {
      this.router.navigate(['/EVENT-APPROVAL'])
      console.log('approved!')
    }, (erro) => {
      console.log("error")
    })
  }
}

我找不到代码中的错误,因为没有显示错误或任何错误,它甚至在正确的区域更新了正确的事件,但是它只是不保存或更新Mongo DB数据库上的任何内容。 该怎么办?

0 个答案:

没有答案