How to embed TradingView into Angular 8 project?

后端 未结 1 1739
故里飘歌
故里飘歌 2021-01-28 13:15

I am interested to know how can I embed the following TradingView\'s code to my Angular 8 project?


相关标签:
1条回答
  • 2021-01-28 13:58

    I could solve my problem like this:

    1. I created a new component in my project and named it tradingview. Then I added the following code into the tradingview.component.ts file:
    import { Component, OnInit, AfterViewInit } from '@angular/core';
    
    
    declare const TradingView: any;
    
    @Component({
      selector: 'app-tradingview',
      templateUrl: './tradingview.component.html',
      styleUrls: ['./tradingview.component.scss']
    })
    
    
    
    export class TradingviewComponent implements OnInit, AfterViewInit {
    
      constructor() { }
    
      ngOnInit() {
      }
    
      ngAfterViewInit(){
        new TradingView.widget(
          {
          "width": 980,
          "height": 610,
          "symbol": "NASDAQ:AAPL",
          "timezone": "Etc/UTC",
          "theme": "Light",
          "style": "1",
          "locale": "en",
          "toolbar_bg": "#f1f3f6",
          "enable_publishing": false,
          "withdateranges": true,
          "range": "ytd",
          "hide_side_toolbar": false,
          "allow_symbol_change": true,
          "show_popup_button": true,
          "popup_width": "1000",
          "popup_height": "650",
          "no_referral_id": true,
          "container_id": "tradingview_bac65"
        }
          );
      }
    
    }
    

    Then I added following code into the tradingview.component.html file:

    <!-- TradingView Widget BEGIN -->
    <div class="tradingview-widget-container">
        <div id="tradingview_bac65"></div>
        <div class="tradingview-widget-copyright"><a href="https://www.tradingview.com/symbols/NASDAQ-AAPL/" rel="noopener" target="_blank"><span class="blue-text">AAPL Chart</span></a> by TradingView</div>
        <script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
        <script type="text/javascript">
    
        </script>
      </div>
      <!-- TradingView Widget END -->
    

    And seems it works fine!

    0 讨论(0)
提交回复
热议问题