I embed a chart widget and want to render the chart dynamically by passing value from a dropdown menu into the chart's symbol as data reference. The app works, but the console log shows the error right from initializing the view.
Here is my code:
Component:
export class TradeChartComponent implements OnInit, AfterViewInit {
@Output() emitValue: EventEmitter<string> = new EventEmitter<string>();
selectedValue: any;
constructor(
private http: HttpClient,
private apiService: ApiService,
@Inject(PLATFORM_ID) private platformId: Object
) {}
selectPair(pair) {
// tslint:disable-next-line:no-unused-expression
const widget = new TradingView.widget({
'container_id': 'technical-analysis',
'autosize': true,
'symbol': pair,
'interval': '120',
});
}
onChange(event: any) {
const widget = this.selectPair(event.target.value);
this.emitValue.emit(this.selectedValue);
}
ngOnInit() {
this.selectPair('BTCUSD');
}
ngAfterViewInit() {
this.onChange(event);
}
}
View:
<select (change)="onChange($event)" class="form-control" [(ngModel)]="selectedValue">
<option value="BTCUSD">BTC/USD</option>
<option value="ETHUSD">ETH/USD</option>
</select>
<div id="technical-analysis" style="height: 280px"></div>