Вывод значения объекта в Angular
Люди добрые подскажите пожалуйста как вывести данные объекта (type: Object)
Нужно вывести именно "name", "shortInfo","fullInfo"
При попытке вывести так {{item.body.name}} как обычный json Получаю ошибку
Property 'name' does not exist on type 'object'.ngtsc(2339) posts-view.component.ts(11, 26): Error occurs in the template of component PostsViewComponent. any
Как это лечится ?
Стэк MEAN. Начну с Mongo, поехали:
БД:
{
"_id": {
"$oid": "648802bebb1a6e6e0feb95ea"
},
"title": "test",
"body": {
"name": "output test",
"shortInfo": "lorem ipsum",
"fullInfo": "Full lorem"
}
}
Mongoose Model:
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const datasSchema = new Schema({
title: {
type: String,
required: true
},
body: {
type: Object,
required: true
}
})
module.exports = mongoose.model('datas', datasSchema)
Client -> interfaces.ts
export interface Datas {
title: string
body: object
}
Client -> posts-view.component.ts
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { Category, Datas } from 'src/app/shared/intefaces';
import { CategoriesService } from 'src/app/shared/services/categories.service';
import { DatasService } from 'src/app/shared/services/datas.service';
@Component({
selector: 'app-posts-view',
templateUrl: './posts-view.component.html',
styleUrls: ['./posts-view.component.css']
})
export class PostsViewComponent implements OnInit {
categories$!: Observable<Category[]>;
datas$!: Observable<Datas[]>;
constructor(private categoriesService: CategoriesService,
private dataServise: DatasService) { }
ngOnInit(): void {
this.categories$ = this.categoriesService.fetch(),
this.datas$ = this.dataServise.fetch()
}
}
Client -> posts-view.component.html
<section class='FlexContainer' *ngIf="datas$ | async as datas; else loader">
<div class="app-card" *ngFor="let item of datas">
<div class="app-card__subtext">{{item.body}}</div>
</div>
</section>