Utilizing an external 3rd party script, I am trying to trigger a function called show_end_screen
(found below)
Within my component
import { Router } from '@angular/router';
import { init_game, start_game, stop_game } from '../../assets/js/game';
@Component({})
export class PlayComponent implements OnInit {
constructor(public router:Router) {}
ngOnInit() {
init_game(this.show_end_screen) // load ready
}
show_end_screen(data){
console.log(data) //this works
this.router.navigate(['play']); //"this" is undefined
}
}
init_game(this.show_end_screen)
<== At this point, I am passing show_end_screen
to the imported script. When the 3rd party script executes show_end_screen(data)
, I am able to successfully log the data
to the console. However, I do not have access to this
or any other Angular reference.
this.router.navigate(['play']);
<== This line triggers a console error
ERROR TypeError: Cannot read property 'nav' of undefined