Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
Getting a window property in Angular 13

Trying to do this in Angular 13:

private _stripe:StripeFactory = window['Stripe']

And it creates this error:

Element implicitly has an 'any' type because index expression is not of type 'number'

Any ideas on how to fix this?

I added:

"suppressImplicitAnyIndexErrors": true,

To tsconfig.json, but the linting errors still persist.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Instead of

"suppressImplicitAnyIndexErrors": true,

in tscongfig.json, it's recommended to use an @ts-ignore comment on the preceding line in the .ts file:

// @ts-ignore
private _stripe:StripeFactory = window['Stripe']

But there is definitely a more 'Angular' way to do what you are trying to do, but I'm not quite sure what that is. Just extrapolating from the name of the type, I'd have a StripeFactory in the StripeService that calls a getStripe() method which has access to your Stripe configuration and key, using that to grab the global Stripe object. You'll have to load Stripe separately and inject the StripeService into the components that need it.

See this dev post for this Stripe specific solution in detail.

Or if you want to stick with window, you can add it to your provider array in the module:

providers: [
  { provide: Window, useValue: window }
]

Then you can inject it directly into your service:

constructor(private window: Window) {
  // ....do whatever you're gonna do
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda