我一直在尝试了解如何为我的应用程序设置 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 。
关于javascript - Controller 中需要模块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46400777/