tradingview / charting-library-examples

Examples of Charting Library integrations with other libraries, frameworks and data transports
MIT License
1.32k stars 744 forks source link

Angular - there was an error when loading the library #366

Open tradingproject19 opened 7 months ago

tradingproject19 commented 7 months ago

Checklist

Describe the bug

ERROR Error: Uncaught (in promise): Error: There was an error when loading the library. Usually this error means the library failed to load its static files. Check that the library files are available at localhost:4200//assets/charting_library/ or correct the library_path option. Error: There was an error when loading the library. Usually this error means the library failed to load its static files. Check that the library files are available at localhost:4200//assets/charting_library/ or correct the library_path option

Expected behavior

It should load the charting_library from assets folder.

Screenshots

Error: image

Angular Assets folder:

image

Trading view constructor: image

Additional context

Why is it not working? We are using the following build:

TT v26.003 (internal id e793d706 @ 2023-10-05T20:30:59.543Z)

tradingproject19 commented 7 months ago

It turned out that save_load_adapter service is causing the issue.

image

This is my constructor code:

const widgetOptions: TradingTerminalWidgetOptions = {
      symbol: this._symbol,
      datafeed: this.datafeed,
      interval: this._interval,
      container: this._chartId,
      library_path: 'assets/charting_library/',
      locale: getLanguageFromURL() || "en",
      disabled_features: [
        "open_account_manager",
        "trading_account_manager",
        "save_chart_properties_to_local_storage",
      ],
      enabled_features: [
        "study_templates",
        "add_to_watchlist",
        "chart_crosshair_menu",
        "tick_resolution",
        "use_localstorage_for_settings",
        "pre_post_market_sessions",
        "show_symbol_logos",
        "watchlist_sections",
      ],
      charts_storage_url: this._chartsStorageUrl,
      charts_storage_api_version: this._chartsStorageApiVersion,
      client_id: this._clientId,
      user_id: this.user.uid,
      fullscreen: this._fullscreen,
      autosize: this._autosize,
      theme: "dark",
      overrides: {
        "paneProperties.background": "#222736",
        "scalesProperties.textColor": "#a6b0cf",
      },
      //debug: true,
      news_provider: async (symbol, callback) => {
        let newItem = await this.dataService.getTickerNews(symbol);
        let result: NewsItem[] = [];
        newItem.results.forEach((item) => {
          let newsItem: NewsItem = {
            published: moment(item.published_utc).valueOf(),
            source: item.publisher.name,
            title: item.title,
            fullDescription: item.description,
            shortDescription: item.description ?? "",
            link: item.amp_url,
          };
          result.push(newsItem);
        });
        console.log(result, "news");
        callback({
          title: `Top Stories`,
          newsItems: result,
        });
      },
      symbol_search_request_delay: 1000,
      custom_css_url: "../../../assets/scss/custom/components/_tvcharts.css",
      widgetbar: {
        news: true,
        details: true,
        watchlist: true,
        datawindow: true
      },
      load_last_chart: true,
      save_load_adapter: this.saveLoadAdapterService
    };

    const tvWidget = new widget(widgetOptions);

If i comment out save_load_adapter: this.saveLoadAdapterService then it works just fine, does anyone know what could be the problem?

romfrancois commented 7 months ago

As shown in that example save_load_adapter is expecting an object. No idea if that's what you had but could be the reason for the error.