【发布时间】:2021-07-22 15:19:21
【问题描述】:
我在 push(post) 时在这个 component.ts 文件中遇到错误。 错误是 'post' 仅指一种类型,但在此处用作值。
import { Component } from '@angular/core';
import { post } from './comp/list/list.module';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
spost:post[]=[];
onpostadd(){
this.spost.push(post);
}
}
这是model.ts文件
export interface post {
title: string;
content : string;
}
【问题讨论】:
-
嗯,它是一种类型。而您将其用作价值。所以错误信息是正确的。我不知道你想要达到什么目的。
-
因为
post是一种类型。你想推动什么价值? -
没看懂能不能改正
标签: javascript angular typescript