繁体   English   中英

无法在角度8中使用写入良好的npm模块

[英]unable to use write-good npm module in angular 8

我正在使用Angular 8.2.4。 我下载了npm模块,写得很好。 当我尝试在测试组件中使用时,出现错误ERROR ReferenceError:未定义匹配。 这是组件代码。

import { Component, OnInit } from '@angular/core';
import * as  writeGood from 'write-good';

@Component({
  selector: 'app-textnpm',
  templateUrl: './textnpm.component.html',
  styleUrls: ['./textnpm.component.css']
})
export class TextnpmComponent implements OnInit {
  testString: string;
  constructor() { }

  ngOnInit() {
    this.hello();
  }

  public hello() {
    this.testString = writeGood('so so the cat was stolen.');
  }
}

下面是错误的详细信息,

ERROR ReferenceError: match is not defined
    at Object.push../node_modules/weasel-words/weasel.js.module.exports [as fn] (weasel.js:40)
    at write-good.js:101
    at Array.forEach (<anonymous>)
    at writeGood (write-good.js:97)
    at TextnpmComponent.hello (textnpm.component.ts:18)
    at TextnpmComponent.ngOnInit (textnpm.component.ts:14)
    at checkAndUpdateDirectiveInline (core.js:31909)
    at checkAndUpdateNodeInline (core.js:44366)
    at checkAndUpdateNode (core.js:44305)
    at debugCheckAndUpdateNode (core.js:45327)

为了达到预期的效果,请使用以下使用writeGood默认方法的选项

public hello() {
    this.testString = writeGood.default('so so the cat was stolen.');
    console.log(this.testString);
  }

工作代码以供参考-https://stackblitz.com/edit/angular-1jkxhj?file=src/app/app.component.ts

选项2:使用以下行导入写好

导入writeGood = require('write-good');

https://stackblitz.com/edit/angular-eaf4o9?file=src/app/app.component.ts

请参考此链接,以获取有关使用功能或类而不是模块或对象的导出来导入javascript库的更多详细信息。

TypeScript中的“导入自”和“导入需要”之间的区别

暂无
暂无

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

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