[英]'post' only refers to a type, but is being used as a value here
I am getting errors in this component.ts file at push(post).我在 push(post) 时在这个 component.ts 文件中遇到错误。 the error is 'post' only refers to a type, but is being used as a value here.错误是“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);
}
}
this is the model.ts file这是model.ts文件
export interface post {
title: string;
content : string;
}
It is exactly as it says: You're only exporting an interface (which is just a type) post
, not an actual value.正如它所说的那样:您只是导出接口(只是一种类型) post
,而不是实际值。 Therefore you can't use it as a value.因此,您不能将其用作值。
Your onpostadd()
probably expects post
as an argument that you didn't add.您的onpostadd()
可能希望post
作为您未添加的参数。
Also, it's quite common to CamelCase type names, similar to classes, eg use Post
instead.此外,CamelCase 类型名称也很常见,类似于类,例如使用Post
代替。 This makes it hard to confuse it with lowercase variable names.这使得它很难与小写变量名混淆。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.