[英]unable to use write-good npm module in angular 8
I am using Angular 8.2.4. 我正在使用Angular 8.2.4。 I download the npm module write-good.
我下载了npm模块,写得很好。 When I try to use in my test component i am getting error ERROR ReferenceError: match is not defined.
当我尝试在测试组件中使用时,出现错误ERROR ReferenceError:未定义匹配。 Here is the component code.
这是组件代码。
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.');
}
}
Below is the error details, 下面是错误的详细信息,
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)
To achieve expected result , use below option of using default method of writeGood 为了达到预期的效果,请使用以下使用writeGood默认方法的选项
public hello() {
this.testString = writeGood.default('so so the cat was stolen.');
console.log(this.testString);
}
working code for reference - https://stackblitz.com/edit/angular-1jkxhj?file=src/app/app.component.ts 工作代码以供参考-https://stackblitz.com/edit/angular-1jkxhj?file=src/app/app.component.ts
Option 2: Use below line for importing write-good 选项2:使用以下行导入写好
import writeGood = require('write-good'); 导入writeGood = require('write-good');
https://stackblitz.com/edit/angular-eaf4o9?file=src/app/app.component.ts https://stackblitz.com/edit/angular-eaf4o9?file=src/app/app.component.ts
Please refer this link for more details on import of javascript librairies with export of a function or class instead of modules or objects 请参考此链接,以获取有关使用功能或类而不是模块或对象的导出来导入javascript库的更多详细信息。
Difference between `import from` and `import require` in TypeScript TypeScript中的“导入自”和“导入需要”之间的区别
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.