简体   繁体   English

Angular 2的高图表-在ChartComponent上找不到指令注释

[英]highcharts for Angular 2 - No Directive annotation found on ChartComponent

I'm trying to get highcharts for Angular 2 to work with my project. 我正在尝试让Angular 2与我的项目一起工作。 However, when I add the CHART_DIRECTIVES to my directives array in @Component , I get the error in my browser console: 但是,当我将CHART_DIRECTIVES添加到@Component directives数组中时,在浏览器控制台中出现错误:

EXCEPTION: Error: Uncaught (in promise): No Directive annotation found on ChartComponent 例外:错误:未捕获(按承诺):在ChartComponent上找不到指令注释

Does anyone know what this means and how to go about fixing this?? 有谁知道这意味着什么以及如何解决这个问题?

EDIT: I'm trying to incorporate this chart package: https://www.npmjs.com/package/angular2-highcharts . 编辑:我正在尝试合并此图表包: https : //www.npmjs.com/package/angular2-highcharts I added CHART_DIRECTIVES by following the instructions on that site with: 我按照该站点上的说明添加了CHART_DIRECTIVES:

import {Http, Headers, Response, HTTP_PROVIDERS} from 'angular2/http';
import {Component, Injectable} from 'angular2/core';
import {CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/common';
import {Router} from 'angular2/router';
import {Observable} from 'rxjs/Rx';
import {Routes} from '../routes.config';

import { CHART_DIRECTIVES } from 'angular2-highcharts';

@Component({
    selector: 'home',
    templateUrl: './app/home/home.html',
    directives: [CHART_DIRECTIVES, CORE_DIRECTIVES, FORM_DIRECTIVES],
    providers: [
        HTTP_PROVIDERS
    ]
})

According to your use case it seems you havn't add import {CHART_DIRECTIVES} from './ng2-charts.ts'; 根据您的用例,您似乎没有import {CHART_DIRECTIVES} from './ng2-charts.ts';添加import {CHART_DIRECTIVES} from './ng2-charts.ts'; this line while imorting chart in your .ts file. 在将图表添加到.ts文件中时显示此行。

Apart from this if you are going to use charts in angular2 you can Refer here 除此之外,如果要在angular2中使用图表,可以在这里参考

Working Example 工作实例

I was facing the same issues. 我面临着同样的问题。 I was able to resolve it by upgrading my application to use the latest RC version of angular2. 通过升级应用程序以使用最新的RC版本的angular2,我能够解决该问题。

The latest release 0.1.0 of angular2-highcharts is now upgraded to the rc.1 (RC version). angular2-highcharts的最新版本0.1.0现在已升级到rc.1 (RC版本)。

I think it's a compatibility issue here even though you import the Component annotation is imported from angular library, it fails to identify it. 我认为这是一个兼容性问题,即使您导入的组件注释是从角度库中导入的,也无法对其进行识别。 You are trying to use an older angular2 version while the angular2-highcharts that we use is based on the latest release of angular2 which has a lot of breaking changes. 您正在尝试使用较旧的angular2版本,而我们使用的angular2-highcharts基于最新版本的angular2,它具有很多重大更改。

Change Log: https://github.com/angular/angular/blob/master/CHANGELOG.md 更改日志: https : //github.com/angular/angular/blob/master/CHANGELOG.md

/// <reference path="../../../../node_modules/angular2/typings/browser.d.ts" />

import {Component} from '@angular/core';
import {CHART_DIRECTIVES} from 'angular2-highcharts';

@Component({
    selector: 'simple-chart',
    directives: [CHART_DIRECTIVES],
    templateUrl: 'templates/simple_chart.html'
})
export class SimpleChart {
    constructor() {
        this.options = {
            title : { text : 'simple chart' },
            series: [{
                data: [29.9, 71.5, 106.4, 129.2],
            }]
        };
    }
    options: Object;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM