Does anyone know how to implement a scrollspy in Angular 2? I have looked for some example of some Plunkr or something but I could not find anything to use.
Does anyone know how to implement a scrollspy in Angular 2? I have looked for some example of some Plunkr or something but I could not find anything to use.
I used it and it worked for me. link
Anyway, if it does not work for you, remember that if you import $ (Jquery) you can work with Jquery libraries, although it is not optimal, but it can always help you. Here is a Jquery library to use ScrollSpy too: link
To use Jquery in Angular 2,4 and 5 you must do the following.
In your index.html add the library
In your component declare the $ library to be available to use.
import { Component } from '@angular/core';
declare var jquery:any;
declare var $ :any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'angular 4 with jquery';
toggleTitle(){
$('.title').slideToggle(); //
}
}
And then in your view you normally use it in the html with the event (click), as you would use it without Angular.
I hope it serves you!