javascript - Controller 中需要模块错误

标签 javascript angularjs node.js express stripe-payments

我一直在尝试了解如何为我的应用程序设置 Stripe,但在模块的实现方面遇到问题。通常,当使用模块时,我会要求它位于文件顶部才能使用它,但是当我在 paymentCtrl 文件中执行此操作时,它不起作用,并且出现以下两个错误:我应该在哪里声明它以便我能够使用它?正如您所看到的,我对此很陌生,并且想了解如何构建它以便付款正常进行。

错误:

require is not defined at paymentCtrl.js:1

Failed to instantiate module paymentController due to: Error: [$injector:nomod] Module 'paymentController' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

付款控制:

var stripe = require('stripe')('sk_test_....');

angular.module('paymentController', [])


.controller('paymentCtrl', function($scope) {


});

app.js:

angular.module('userApp', ['appRoutes', 'userControllers', 'userServices', 'ngAnimate', 'mainController', 'authServices', 'managementController', 'paymentController'])

.config(function($httpProvider) {
    $httpProvider.interceptors.push('AuthInterceptors');
});

最佳答案

Stripe 的Node.js library旨在在服务器端代码中使用。您不应将其嵌入到客户端代码中,因为这样做会泄露您的 secret API key 。

在您的客户端代码中,您可以使用 CheckoutElements收集和标记支付信息。

关于javascript - Controller 中需要模块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46400777/

相关文章:

javascript - window.onload 在网页加载之前执行

javascript - Autofit 谷歌使用地点 ID 映射多个标记

javascript - 对 angularjs 中的所有函数使用 1 种方法缩短为一个函数

javascript - 创建指令并以 Angular 隔离范围

javascript - 每秒轮换数组

javascript - 测试不同值的许多条件的干净方法?

javascript - AngularJS 在 lang 更改时更改语言环境文件

node.js - 在 node.js 中,如何将变量传递给 :stylus filter from jade?

node.js - 无法使用 UpdateItem 从列表中删除元素

node.js - Node HTTP 服务器的最大性能?