问题
I am interested to know how can I embed the following TradingView's code to my Angular 8 project?
<!-- 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">
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"
}
);
</script>
</div>
<!-- TradingView Widget END -->
I also like to know how can I feed my data from a .csv
file or from a URL address(like BTC online price).
回答1:
I could solve my problem like this:
- I created a new component in my project and named it
tradingview
. Then I added the following code into thetradingview.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!
来源:https://stackoverflow.com/questions/59010646/how-to-embed-tradingview-into-angular-8-project