简体   繁体   中英

error TS2304: Cannot find name 'trim' in Angular 5

I have following function

add(playload) {
    return this.http.post(`/api/v1/cards.json`, { text: trim(playload) });
}

It output following.

error TS2304: Cannot find name 'trim'.

How can I solve this error?

The syntax of using trim is string.trim() where string is any string value in which you want to trim the whitespaces. So. you need to use payload.trim() like this, (and not trim(payload) )

add(playload) {
    return this.http.post(`/api/v1/cards.json`, { text: playload.trim() });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM