如何通过角度5中的HttpClient恢复对象的更新

时间:2018-05-09 12:20:59

标签: angular httpclient angular5

我更新了联系人,但无法取回更新的对象来更新视图,而是获得了 Bootstrap includes a responsive, mobile first fluid grid system that appropriately scales up to 12 columns as the device or viewport size increases. It includes predefined classes for easy layout options, as well as powerful mixins for generating more semantic layouts.

服务从API获取数据

{n: 1, nModified: 1, ok: 1}

ContactComponent

export class ContactService {

  url: string = 'http://localhost:3000/contacts/';

  constructor(private http: HttpClient) {
  }

  async Update(contact: Contact) {
    return await this.http.put(this.url.concat(contact._id), contact);
  }
}

API调用

export class ContactComponent implements OnInit {

  async update() {
    const updatingContact = await this.contact.Update(contact);
    updatingContact.subscribe(result => {          
      console.log(result); // {n: 1, nModified: 1, ok: 1}
    })
  }
}

如何在router.put('/:id', async (req, res) => { try { const contact = await Contact.updateOne({ _id: req.params.id }, { firstname: req.body.firstname, phone: req.body.phone }); res.json(contact); } catch (err) { debug(err.message) } }) 方法中获取更新的对象以更新视图?

1 个答案:

答案 0 :(得分:0)

可能是别人遇到这个问题。

如何改进我的代码以获取更新的对象

Ext.getCmp('datef').expand();