【问题标题】:Angular 5 component usageAngular 5 组件使用
【发布时间】:2018-09-03 21:13:00
【问题描述】:

我是 Angular 5 的新手,我下载了这个入门模板:

Angular 5 - Firebas starter template

我有一个仪表板组件,我想在其中实现一个 chartjs 组件。

我的dashboard.module.ts:

import { DashboardPageComponent } from './dashboard-page.component';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

@NgModule({
    imports: [
        RouterModule.forChild([
            { path: '', pathMatch: 'full', component: DashboardPageComponent },
        ]),
    ],
    declarations: [DashboardPageComponent],
})
export class DashboardModule {}

这里是dashboard.component.html 模板:

 <div class="container">
    <h1>Your Todo List</h1>
    <ul class="list-group">
        <p>test</p>
    </ul>

    // HERE I WANT TO USE THE CHART COMPONENT
    <line-chart-component></line-chart-component>
</div>

这是折线图组件:

import { Component, OnInit } from '@angular/core';
import * as Chart from 'chart.js'

@Component({
    selector: 'line-chart-component',
    templateUrl: './line-chart.component.html'
})
export class LineChartComponent {
    constructor() { }
}

还有折线图html:

    <div class="container">
      <h1>TESTCOMPONENT</h1>
    </div>

还有图表模块:

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { LineChartComponent } from './line-chart.component';

@NgModule({
    declarations: [LineChartComponent],
    // export: [LineChartComponent],
})
export class LineChartModule {}

但是导出声明不能分配给“NgModule”类型的参数

如何在仪表板组件中使用图表组件?

【问题讨论】:

  • 是出口,不是出口
  • @marko 比它抛出这个错误:错误:'line-chart-component' is not a known el...,...}
  • 你引用的链接失效了

标签: angular typescript


【解决方案1】:

这是exports 不是export:

@NgModule({
    declarations: [LineChartComponent],
    exports: [LineChartComponent],
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-12
    • 2018-10-09
    • 2018-09-24
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 1970-01-01
    • 2018-10-31
    相关资源
    最近更新 更多