简体   繁体   中英

Angular 6, a tag with href using #link links to base page not the current page

The issue I am currently facing is that the link generated by the a tag links to the base page. As you can see in the image it links to

localhost:3000#hello

My goal is to get it to link to

localhost:3000/bodyText#hello

The a tag will come from an external source so my test example mimics that. I have so far been using innerHTML directive to put the external html in the html template.

Here is the component I am working with

import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-test',
template: '<div [innerHTML]=html></div>',
 styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {

constructor() { 
}

html = "<a href=\"#hello\" title=\"hello\">A tag </a> <a name=\"hello\" id= \"hello\"/> "

ngOnInit() {
}

}

这是我的页面当前的样子

我通过在HTML标记中添加点击处理程序,然后使用scrollIntoViewgetElementById而不是使用标记来解决此问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM