[ad_1]
I've started writing app which uses NodeJS with Express and Mongoose to serve API and Angular4 as frontend framework. I have problem with retrieving mongoose model "_id" property. I've defined interface in my angular app to describe object:
export interface Category
_id: string,
name: string,
I have route which returns category to front:
public show(req: Request, res: Response, next: NextFunction)
const id = req.param('id');
console.log(id);
Category.findOne(_id: id)
.then(category =>
res.status(200).send('success': true, 'data': category, 'msg': 'OK')
)
.catch(error =>
res.status(400).send(success: false, msg: error.message);
)
But when i want to do console.log on category._id I'm getting an error
Property '_id' does not exist on type 'Category'.
Here is angular service function:
getCategory(id: string): Promise<Category>
let category: Category;
return this.http.request(this._categoriesUrl + 'show/' + id)
.toPromise()
.then(response =>
category = response.json().data as Category;
console.log(category._id);
return category;
)
.catch( error =>
return category;
)
Category is set because if I log whole object it's ok.
I've started this app with angular-cli, here is tsconfig.json if it helps:
"compileOnSave": false,
"compilerOptions":
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
[ad_2]
لینک منبع