import { Component, Renderer2, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
constructor(private renderer: Renderer2) {}
ngOnInit() {
this.changeIcon('/path/to/new/favicon.ico');
}
changeIcon(iconPath: string) {
const link = this.renderer.selectRootElement('link[rel*="icon"]');
this.renderer.setAttribute(link, 'href', iconPath);
}
}
angular16 title的图标 动态替换<link rel=“icon“>标签的href属性
最新推荐文章于 2024-11-05 15:31:54 发布