I am using angular 6 to build website.Actually I want to run script on element when page is loaded.As angular ngOnit() runs script before content is loaded so I an getting problems.I found angular.element(function ()) that might solve this problem.but when I installed and imported angular into my project but I got error: Error I got is:
Error:Module not found:can't resolve'../../../node_modules/@types/angular' in 'C:\Users\name\WebProject\src\app\sales'
I also imported it to my perticular component like this:
import * as angular from '../../../node_modules/@types/angular';
My code to run script after content load is:
ngOnInit() { angular.element(function () { alert('page loading completed'); }); }
It will be great if anyone help me out on thi or suggest me aany other way to achieve what I want. Thanks.
angular.element()is AngularJS, Angular's predecessor, so that won't work. I don't understand yet whyngOnInit()doesn't work for you, that's the textbook place for running scripts when the element is used on the page. - J.P. ten Berge