Scroll Spy in angular 2

0

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.

    
asked by Oscar Alonso Rueda Ruiz 09.05.2017 в 01:08
source

1 answer

1

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!

    
answered by 01.02.2018 в 21:16