Typescript自定义静态函数不会使用Webpack provider插件调用错误

时间:2019-10-12 14:22:24

标签: angular typescript webpack

ValidationHelper.ts

declare var numeral: any;

export class ValidationHelper {
    constructor() {
    }
    //---------------------------CustomCDBL----------------------------------
    CustomCDBL(val: any) {
        if (val == undefined) {
            return 0;
        }
        else if (val == null) {
            return 0;
        }
        else if (val == "") {
            return 0;
        }
        else {
            var newVal = numeral(val).format('0.00');
            return Number(newVal);
        }
    }
}

Webpack.config.js

new webpack.ProvidePlugin({
            numeral: 'numeral',
            ValidationHelper: path.resolve(__dirname, './src/app/_general/ValidationHelper')

我想使用providerplugin将我的助手类“ ValidationHelper.ts”提供给其他模块,但是我的函数未执行并显示错误。

调用函数时Chrome中出现错误。

*ERROR TypeError: ValueHelper.CustomString is not a function*

0 个答案:

没有答案