import { AfterViewInit , Component , ElementRef , OnInit } from '@angular/core' ; @ Component ( { selector : 'app-home' , templateUrl : './home.component.html' , styleUrls : [ './home.component.css' ] , providers : [ ] } ) export class HomeComponent implements OnInit , AfterViewInit { constructor ( private elementRef ) { } ngOnInit ( ) { } ngAfterViewInit ( ) { let scriptElement ; scriptElement = document . createElement ( "script" ) ; scriptElement . type = "text/javascript" ; scriptElement . src = "http://platform.twitter.com/widgets.js" ; this . elementRef . nativeElement . appendChild ( scriptElement ) ; } }