How do I create a component in Angular 2 that impo

2019-06-27 04:19发布

问题:

I am fairly new to Angular 2 and TypeScript. I am using AngularCLI and NPM to create my Angular Project. I have used NPM to install the quill node module into my project. I am now trying to create a component in which I can customize my quill editor through their API.

I am trying to use:

import * as Quill from 'quill'; 

This is returning a 'cannot find quill module' error.

I have already added

"": "0.0.26",
"quill": "^1.0.4",

to package.json as dependencies.

回答1:

I tried to reproduce your issue in a pet Angular CLI project generated with the ng new command, and it worked fine. Here is the code:

import { Component } from '@angular/core';
import * as Quill from 'quill';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app works!';

  ngOnInit() {
    console.log(Quill);
  }
}
And here's the output I get: Image Link

Go to you project's node_modules folder and look for a folder named quill, anyway, even if it is there, delete the node_modules folder and run npm i command again