Reputation: 15
Hi Have a Bootstrap navbar component with javascript like :
https://bootsnipp.com/snippets/a35lo
In above example, It has HTML, CSS, and JS, If I want to use above in Angular 4, How can I use above JS directly instead of converting it into typescript.
Upvotes: 0
Views: 108
Reputation: 1211
First you need to load js file using scriptLoaderService in your component. then you can use any JQuery or third-party library code in your ts file.
(<any>$('body')).scrollspy({
target: '#navbar-collapsible',
offset: 50
});
/* smooth scrolling sections */
(<any>$('a[href*=#]:not([href=#])')).click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 50
}, 1000);
return false;
}
}
});
Upvotes: 1