Using HTML anchor link #id in Angular 6

前端 未结 7 1708
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 01:34

I am working with Angular 6 project in which I have disabled/removed hash-location-strategy which removes # from URL.

due to this change the link having:

<         


        
7条回答
  •  死守一世寂寞
    2020-11-29 01:44

    This is for Angular 9, but, I am sure the community will benefit this,

    You can use Location in the @angular/common to get the current path.

    Let's say you have the following element with an id to focus

    I am only showing extracted code blocks here.

    import { Location } from '@angular/common';
    
    constructor(private location: Location) { }
    
    this.location.path() + '#bring-me-to-the-focus'; 
    

    I am sure this will help someone :)

    Cheers.

提交回复
热议问题