如何在Ionic 3中使用节点模块creditcard?
实现示例包括:
var Card = require('creditcards/card')
var card = Card([visa])
card.isValid('4242424242424242')
// => true
var expiration = require('creditcards/expiration')
expiration.isPast(10, 2010)
// => true
但是使用Ionic 3时出现错误
Cannot find name 'require'.
,在这里的ionic中我发现了与lodash
类似的问题:https://github.com/ionic-team/ionic/issues/8274我尝试发布解决方案,但似乎没有任何效果。
首先,我尝试添加
import card from 'creditcards/card';
这是离子代码:
import { Component } from '@angular/core';
import card from 'creditcards/card';
@Component({
templateUrl: 'creditcard.html'
})
export class CreditcardPage {
creditContent: string;
constructor() {
this.creditContent = card.isValid(`42424242424242`);
}
}
我收到错误
ReferenceError: card is not defined
。我尝试了
import 'creditcards/card';
:import { Component } from '@angular/core';
import 'creditcards/card';
@Component({
templateUrl: 'creditcard.html'
})
export class CreditcardPage {
creditContent: string;
constructor() {
this.creditContent = card.isValid(`42424242424242`);
}
}
我收到错误
Uncaught ReferenceError: Card is not defined
SO中还有一个帖子:Typescript Error Cannot find name 'require'. IONIC 3。这没有提供相关信息,因为它特定于
@types/node
。 最佳答案
我相信问题出在您的tsconfig文件中。您应包括“类型:[节点]”
关于node.js - 如何在Ionic 3中使用要求信用卡,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49494660/