首页 > 解决方案 > 添加 src 的 Angular 7 构建路径在哪里?

问题描述

我正在使用这个条纹角度来实现条纹信用卡处理。按照网站上的说明操作后,我无法访问 window.Stripe。

这是我的组件文件:

import { Component } from '@angular/core'
import { environment } from '../environments/environment'
import { CreditCardService } from '../_services/creditcard.service'
import { StripeScriptTag } from "stripe-angular"

@Component({
  selector: 'app-stripe',
  templateUrl: './stripe.component.html',
  styleUrls: ['./stripe.component.css']
})
export class StripeComponent {

  private publishableKey:string = `${environment.stripeKey}`;

  constructor(private creditCardService: CreditCardService,
  public StripeScriptTag:StripeScriptTag) {
  console.log('publishable key ',`${environment.stripeKey}` )
  console.log('window.Stripe ', window.Stripe )
  }

错误是,“ ‘Window’类型上不存在属性‘Stripe’。

这段代码放在组件和主索引html中

<script src="https://js.stripe.com/v3/"></script>

这暴露了条纹,但窗口没有找到它。

我读到我应该将该路径添加到 webpack 构建路径。我怎么做?

标签: angularwebpackstripe-paymentsangular7

解决方案


当我将 window.Stripe 替换为 Stripe 时,错误消失并添加了 Stripe:any


推荐阅读