Angular 6,使用#link links 的带有href 的标签指向基页而不是当前页
Angular 6, a tag with href using #link links to base page not the current page
我目前面临的问题是a标签links生成的link到基页。正如您在图片中看到的那样,它 links 到
localhost:3000#hello
我的目标是 link 到
localhost:3000/bodyText#hello
a 标签将来自外部来源,因此我的测试示例模仿了它。到目前为止,我一直在使用 innerHTML 指令将外部 html 放入 html 模板中。
这是我正在使用的组件
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 标记添加点击处理程序然后使用 scrollIntoView and getElementById 而不是使用 a 标记来解决此问题。
我目前面临的问题是a标签links生成的link到基页。正如您在图片中看到的那样,它 links 到
localhost:3000#hello
我的目标是 link 到
localhost:3000/bodyText#hello
a 标签将来自外部来源,因此我的测试示例模仿了它。到目前为止,我一直在使用 innerHTML 指令将外部 html 放入 html 模板中。
这是我正在使用的组件
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 标记添加点击处理程序然后使用 scrollIntoView and getElementById 而不是使用 a 标记来解决此问题。