1

I am new to the angular 5 in fact whole angular 2 concept. i have created new project in visual studio 2017 with angular 5 and .net core. i am trying to use the d3 and ng2-nvd3. i have added packages in npm. i am getting below error when i try to run the page.

below is the error.

NodeInvocationException: Template parse errors: Can't bind to 'options' since it isn't a known property of 'nvd3'. ("<div>
 <nvd3 [ERROR ->][options]="options" [data]="data"></nvd3>
 </div>
 "): ng:///AppModuleShared/HomeComponent.html@1:10 Can't bind to 'data' since it isn't a known property of 'nvd3'. ("<div>
 <nvd3 [options]="options" [ERROR ->][data]="data"></nvd3>
 </div>
 "): ng:///AppModuleShared/HomeComponent.html@1:30 'nvd3' is not a known element: 1. If 'nvd3' 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. ("<div>
 [ERROR ->]<nvd3 [options]="options" [data]="data"></nvd3>
 </div>
 ")

My Package.json is

{
  "name": "HaloManagement.DashBoard",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "test": "karma start ClientApp/test/karma.conf.js"
  },
  "devDependencies": {
    "@angular/animations": "5.2.0",
    "@angular/common": "5.2.0",
    "@angular/compiler": "5.2.0",
    "@angular/compiler-cli": "5.2.0",
    "@angular/core": "5.2.0",
    "@angular/forms": "5.2.0",
    "@angular/http": "5.2.0",
    "@angular/platform-browser": "5.2.0",
    "@angular/platform-browser-dynamic": "5.2.0",
    "@angular/platform-server": "5.2.0",
    "@angular/router": "5.2.0",
    "@ngtools/webpack": "1.5.0",
    "@types/chai": "4.0.1",
    "@types/jasmine": "2.5.53",
    "@types/webpack-env": "1.13.0",
    "angular2-router-loader": "0.3.5",
    "angular2-template-loader": "0.6.2",
    "aspnet-prerendering": "^3.0.1",
    "aspnet-webpack": "^2.0.1",
    "awesome-typescript-loader": "3.2.1",
    "bootstrap": "3.3.7",
    "chai": "4.0.2",
    "css": "2.2.1",
    "css-loader": "0.28.4",
    "d3": "^3.5.17",
    "nvd3": "^1.8.6",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.9",
    "expose-loader": "0.7.3",
    "extract-text-webpack-plugin": "2.1.2",
    "file-loader": "0.11.2",
    "html-loader": "0.4.5",
    "isomorphic-fetch": "2.2.1",
    "jasmine-core": "2.6.4",
    "jquery": "3.2.1",
    "json-loader": "0.5.4",
    "karma": "1.7.0",
    "karma-chai": "0.1.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-jasmine": "1.1.0",
    "karma-webpack": "2.0.3",
    "ng2-nvd3": "^2.0.0",
    "preboot": "4.5.2",
    "raw-loader": "0.5.1",
    "reflect-metadata": "0.1.10",
    "rxjs": "5.4.2",
    "style-loader": "0.18.2",
    "to-string-loader": "1.1.5",
    "typescript": "2.4.1",
    "url-loader": "0.5.9",
    "webpack": "2.5.1",
    "webpack-hot-middleware": "2.18.2",
    "webpack-merge": "4.1.0",
    "zone.js": "0.8.12"
  },
  "dependencies": {
    "nvd3": "^1.8.6"
  }
}

App.shared.module.ts is looks like below.

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';

import { AppComponent } from './components/app/app.component';
import { NavMenuComponent } from './components/navmenu/navmenu.component';
import { HomeComponent } from './components/home/home.component';
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
import { CounterComponent } from './components/counter/counter.component';

import { NvD3Module } from "ng2-nvd3";

// d3 and nvd3 should be included somewhere
import 'd3';
import 'nvd3';

@NgModule({
    declarations: [
        AppComponent,
        NavMenuComponent,
        CounterComponent,
        FetchDataComponent,
        NvD3Module,
        HomeComponent
    ],
    imports: [
        CommonModule,
        HttpModule,
        FormsModule,
        RouterModule.forRoot([
            { path: '', redirectTo: 'home', pathMatch: 'full' },
            { path: 'home', component: HomeComponent },
            { path: 'counter', component: CounterComponent },
            { path: 'fetch-data', component: FetchDataComponent },
            { path: '**', redirectTo: 'home' }
        ])
    ]
})
export class AppModuleShared {
}
</pre>

home.component.ts looks like below where i am trying to add chart

import { Component, OnInit } from '@angular/core';
import { NvD3Module } from "ng2-nvd3";

import 'd3';
import 'nvd3';

@Component({
    selector: 'home',
    templateUrl: './home.component.html'
})
export class HomeComponent implements OnInit {

    ngOnInit(): void {
    }

    options: any;
    data: any;

    constructor() {
        this.options = {
            chart: {
                type: 'pieChart',
                height: 500,
                x: function (d) {
                    return d.key;
                },
                y: function (d) {
                    return d.y;
                },
                showLabels: true,
                duration: 500,
                labelThreshold: 0.01,
                labelSunbeamLayout: true,
                legend: {
                    margin: {
                        top: 5,
                        right: 35,
                        bottom: 5,
                        left: 0
                    }
                }
            }
        };

        this.data = [
            {
                key: "P60-1",
                y: 500
            },
            {
                key: "P60-2",
                y: 445
            },
            {
                key: "P40",
                y: 225
            },
            {
                key: "P73",
                y: 127
            },
            {
                key: "P71",
                y: 128
            }
        ];

    }
}

App.server.module.ts looks like below

import { NgModule } from '@angular/core';
import { ServerModule } from '@angular/platform-server';
import { AppModuleShared } from './app.shared.module';
import { AppComponent } from './components/app/app.component';

@NgModule({
    bootstrap: [ AppComponent ],
    imports: [
        ServerModule,
        AppModuleShared
    ]
})
export class AppModule {
}

and home.component.html is look like this

<div>
    <nvd3 [options]="options" [data]="data"></nvd3>
</div>

what i am doing wrong?

1 Answers1

-1

You need to add NvD3Module to list of your imports not declarations.

@NgModule({
  imports: [ // import Angular's modules 
    ...
    NvD3Module
    ...
  ],
})
Mateusz
  • 232
  • 1
  • 11
  • Well that definitely should be in imports, what errors do you get when having that in imports? – Mateusz Mar 26 '18 at 12:19
  • In this template it's using Web pack does that impact anything? – Sandip Dobariya Mar 26 '18 at 12:57
  • Have you tried importing in in to the root `AppModule`(or whatever you've named it)? – Mateusz Mar 26 '18 at 13:01
  • what ever code that i shared it AppModueshared whch is getting imported by AppModule. where you are mentioning. i have added AppModue code in question just now. – Sandip Dobariya Mar 26 '18 at 13:21
  • Yeah I guessed you do that, can you just try adding `NvD3Module` to `AppModule` imports instead of `AppModuleShared`? – Mateusz Mar 26 '18 at 13:24
  • I have added there in appModule as well but still same error after removing from i have removed from the AppModuleShared. – Sandip Dobariya Mar 26 '18 at 13:31
  • Weird, have you tried that minimal setup showed on github? https://github.com/krispo/ng2-nvd3 – Mateusz Mar 26 '18 at 13:34
  • i just tried in standalone small app using minimal settings. it is working over there. i am not sure what is missing here. in minimal app i have added packages and then put all imports and then in app.component.ts i have putted sample data and in html put directive. – Sandip Dobariya Mar 26 '18 at 13:52