简体   繁体   English

“post”仅指一种类型,但在此处用作值

[英]'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.

相关问题 导出时类型“仅指一种类型,但在此处用作值” - Type “only refers to a type, but is being used as a value here” when exporting “承诺”仅指类型,但在此处用作值 - 'Promise' only refers to a type, but is being used as a value here “'输出'仅指一种类型,但在此处使用了一个值”错误 - "'Output' only refers to a type, but is being used a value here" error 'MapEditServiceConfig'仅引用类型,但在此处用作值 - 'MapEditServiceConfig' only refers to a type, but is being used as a value here 元素指的是一个值,但在这里被用作类型 - element refers to a value, but is being used as a type here 'ItemIsLoading'on指的是一种类型,但此处被用作值 - 'ItemIsLoading' on refers to a type, but is being used as a value here 指的是一个值,但在这里被用作一个类型 - refers to a value, but is being used as a type here IFormContext 只引用一个类型,但在这里用作一个值 - IFormContext only refers to a type, but is used as a value here 打字稿错误:'RRule' 仅引用类型,但在此处用作命名空间 - typescript error: 'RRule' only refers to a type, but is being used as a namespace here ng-multiselect-dropdown - 'IDropdownSettings' 仅指一种类型,但在此处用作值 - ng-multiselect-dropdown - 'IDropdownSettings' only refers to a type, but is being used as a value here
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM