【问题标题】:Angular 6, a tag with href using #link links to base page not the current pageAngular 6,一个带有href的标签,使用#link链接到基本页面而不是当前页面
【发布时间】:2018-10-03 07:14:45
【问题描述】:

我目前面临的问题是 a 标签生成的链接链接到基本页面。正如您在图片中看到的那样,它链接到

localhost:3000#hello

我的目标是让它链接到

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() {
}

}

【问题讨论】:

  • 你如何设置base-href?你能证明吗
  • 在 index.html 中我有 如果你指的是这个

标签: html angular innerhtml


【解决方案1】:

我通过向 html 标记添加点击处理程序然后使用 scrollIntoViewgetElementById 而不是使用 a 标记解决了这个问题。

【讨论】:

    猜你喜欢
    • 2021-12-29
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 2013-01-17
    • 1970-01-01
    • 2021-05-04
    • 2020-04-29
    • 2021-11-28
    相关资源
    最近更新 更多