Giter VIP home page Giter VIP logo

Comments (11)

jatingajera31 avatar jatingajera31 commented on June 25, 2024 1

@hanspagel I check #1340 issue but still I am getting problem.
I already add screenshot.

from scalar.

amritk avatar amritk commented on June 25, 2024 1

Alright I tested it and you are correct, even with the new events we still can't get it working in angular due to attaching the references to the body instead of the dom element inside the view. I think we should just make an angular integration at some point. I will open a ticket

from scalar.

hanspagel avatar hanspagel commented on June 25, 2024 1

Great you‘ve found a workaround! 🙌 As a general solution for our published version I’d still take the approach mentioned above:

#1724 (comment)

from scalar.

hanspagel avatar hanspagel commented on June 25, 2024

Thanks for bringing this up!

Related issue: #1340

from scalar.

hanspagel avatar hanspagel commented on June 25, 2024

Sure! Just wanted to cross link both issues.

We’re using vite-plugin-css-injected-by-js to inject the styles. I think we could use styleId and a custom injectCode function to make sure the style tag is only added once:

https://github.com/marco-prontera/vite-plugin-css-injected-by-js?tab=readme-ov-file#injectcode-function

from scalar.

amritk avatar amritk commented on June 25, 2024

@hanspagel @jatingajera31 there is a fix possible for this now with the new events. Just place the script tag outside of the page so it only gets loaded once, then you can trigger the custom event when you navigate to the page to reload the references

document.dispatchEvent(new Event('scalar:reload-references'))

but yes we should also only load the js and styles once

from scalar.

amritk avatar amritk commented on June 25, 2024

@jatingajera31 if you want to put up a minimal reproduction or just your code in general I can try and help

from scalar.

jatingajera31 avatar jatingajera31 commented on June 25, 2024

@amritk here is the code
angular component file

`import { AfterViewInit, Component, OnDestroy, OnInit, Renderer2 } from '@angular/core';

@component({
selector: 'app-api-list',
standalone: true,
imports: [],
templateUrl: './api-list.component.html',
styleUrls: ['./api-list.component.scss'],
})
export class ApiListComponent implements OnInit, AfterViewInit, OnDestroy {
constructor() { }

ngOnInit(): void {
this.loadScript('https://cdn.jsdelivr.net/npm/@scalar/api-reference').then((res: any) => {
console.log('res:', res);
}).catch(error => {
console.error('Error loading script:', error);
});
}

ngOnDestroy(): void {
}

ngAfterViewInit(): void {
}

private loadScript(url: string): Promise {
return new Promise((resolve, reject) => {
const scriptElement = document.createElement('script');
scriptElement.src = url;
scriptElement.onload = () => resolve();
scriptElement.onerror = (error) => reject(error);
document.body.appendChild(scriptElement);
});
}
}`

html code file
<div id="api-reference" data-url="https://petstore3.swagger.io/api/v3/openapi.json" data-proxy-url="https://api.scalar.com/request-proxy"></div>

from scalar.

amritk avatar amritk commented on June 25, 2024

You can track the work here

#1750

from scalar.

jatingajera31 avatar jatingajera31 commented on June 25, 2024

@amritk Thank you for ticket.
I have fix that issue by removing (text/css) appending node from cdn link. I use this ( n.parentNode.removeChild(n))
image
Is this okay?

from scalar.

amritk avatar amritk commented on June 25, 2024

not sure, @hanspagel what do yo think

from scalar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.