Angular 错误:';错误TS2339:属性';数据';不存在于类型';响应';——有棱角的

Angular 错误:';错误TS2339:属性';数据';不存在于类型';响应';——有棱角的,angular,charts,highcharts,angular6,Angular,Charts,Highcharts,Angular6,我是学习Angular 6的新手,当我执行下面的代码时,我会遇到下面的错误。请任何人帮助我解决这个问题 我在浏览器控制台中发现以下错误,并在下面找到文件供您参考。 错误: 控制台错误 Uncaught Error: Template parse errors: Can't bind to 'options' since it isn't a known property of 'chart'. ("<!--The content below is only a placeholder an

我是学习Angular 6的新手,当我执行下面的代码时,我会遇到下面的错误。请任何人帮助我解决这个问题

我在浏览器控制台中发现以下错误,并在下面找到文件供您参考。 错误:

控制台错误

Uncaught Error: Template parse errors:
Can't bind to 'options' since it isn't a known property of 'chart'. ("<!--The content below is only a placeholder and can be replaced.-->
<chart [ERROR ->][options]="options">
      <series>
     </series>
"): ng:///AppModule/AppComponent.html@1:7
'series' is not a known element:
1. If 'series' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("--The content below is only a placeholder and can be replaced.-->
<chart [options]="options">
      [ERROR ->]<series>
     </series>
  </chart>
"): ng:///AppModule/AppComponent.html@2:6
'chart' is not a known element:
1. If 'chart' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("<!--The content below is only a placeholder and can be replaced.-->
[ERROR ->]<chart [options]="options">
      <series>
     </series>
"): ng:///AppModule/AppComponent.html@1:0
    at syntaxError (compiler.js:1016)
    at TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:14813)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:23988)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:23975)
    at compiler.js:23918
    at Set.forEach (<anonymous>)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:23918)
    at compiler.js:23828
    at Object.then (compiler.js:1007)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:23827)
未捕获错误:模板分析错误:
无法绑定到“选项”,因为它不是“图表”的已知属性。("
][选项]=“选项”>
“”:ng:///AppModule/AppComponent。html@1:7
“系列”不是已知元素:
1.如果“系列”是一个角度组件,则确认它是该模块的一部分。
2.若要允许任何元素,请将“无错误模式”添加到此组件的“@NgModule.schemas”。(“--下面的内容只是一个占位符,可以替换。-->
[错误->]
“”:ng:///AppModule/AppComponent。html@2:6
“图表”不是已知元素:
1.如果“图表”是一个角度组件,则确认它是该模块的一部分。
2.若要允许任何元素,请将“无错误模式”添加到此组件的“@NgModule.schemas”。("
[错误->]
“”:ng:///AppModule/AppComponent。html@1:0
在syntaxError(compiler.js:1016)
在TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse(compiler.js:14813)
在JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate(compiler.js:23988)
在JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate(compiler.js:23975)
在compiler.js:23918
在Set.forEach()处
在JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents(compiler.js:23918)
在compiler.js:23828
在Object.then(compiler.js:1007)
在JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileemoduleandcomponents(compiler.js:23827)

当您在AppService中编码时:

getData: any;
getData(): void {
   // DO SOMETHING
}
通过这种方式,您只声明了一个变量。要调用
getData
函数,您应该在AppService中具有如下内容:

getData: any;
getData(): void {
   // DO SOMETHING
}

您是否尝试将
Inject
指令添加到
app.component.ts
文件中?以下是组件构造函数的代码:

constructor(@Inject(AppService) public appService: AppService)
app.component.ts文件更改:

export class AppComponent implements OnDestroy, OnInit {
  title = 'my-project';
  @Input() showMePartially: boolean;
  options: any;
  data: number;
  chart: any;
  dataSubscription: Subscription;
  chartData$: Object;
  constructor(@Inject(AppService) public appService: AppService) {
    this.options = {
      chart: {
        type: 'pie',
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
      },
      //     legend: { enabled: false },
      credits: {
        enabled: false
      },
      tooltip: {
        //     pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
      },
      plotOptions: {
        pie: {
          allowPointSelect: false,
          cursor: 'pointer',
          dataLabels: {
            enabled: false,
            //      format: '<b>{point.name}</b>: {point.percentage:.1f} %',
          }
        }
      },
      series: [{
        name: 'Dispo',
        data: []
      }]
    };
  }

你好,Fire手套,我尝试过,但出现了上述错误。我已更新了问题:哪一行引发了数据错误?@Fire手套第27行src/app/app.component.ts(69,42)中的错误:错误TS2339:属性“data”在类型“Response”上不存在。您能在代码中签名吗?我没有stackoverflow的行号:),请发布您的jsonresponse@firegloves我已经在app.component.ts文件第69行添加了行号,请检查,我得到的是错误,而不是json响应。请使用标记行控制台错误在上面的问题中找到它。我认为您的问题是以下代码:data.data。请发布您的json若要查看其包含的内容,请立即尝试,一旦其完成,将让您知道HI Daniel im在src/app/app.component.ts(67,45)中出现以下错误错误:错误TS2339:类型“AppService”上不存在属性“subscribe”。在this.dataSubscription=this.appService.subscribe((数据)行出现此问题是因为您没有在app.service中定义
subscribe()
函数,但这是另一个问题。我的答案解决了您的问题,因此请将其标记为答案。
getData(): void {
   // DO SOMETHING
}
constructor(@Inject(AppService) public appService: AppService)
export class AppComponent implements OnDestroy, OnInit {
  title = 'my-project';
  @Input() showMePartially: boolean;
  options: any;
  data: number;
  chart: any;
  dataSubscription: Subscription;
  chartData$: Object;
  constructor(@Inject(AppService) public appService: AppService) {
    this.options = {
      chart: {
        type: 'pie',
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
      },
      //     legend: { enabled: false },
      credits: {
        enabled: false
      },
      tooltip: {
        //     pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
      },
      plotOptions: {
        pie: {
          allowPointSelect: false,
          cursor: 'pointer',
          dataLabels: {
            enabled: false,
            //      format: '<b>{point.name}</b>: {point.percentage:.1f} %',
          }
        }
      },
      series: [{
        name: 'Dispo',
        data: []
      }]
    };
  }
 import { Component, Input, Inject, OnInit, OnDestroy  } from '@angular/core';