本文介绍了Angular-更新根index.html中的html属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的index.html中包含以下内容

I have following content in my index.html

<!doctype html>
<html dir="ltr" lang="en">
    <head>
        <meta charset="utf-8">
        <title>Halls Gate</title>
        <base href="/">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="icon" type="image/png" href="assets/img/favicon.png">
        <link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,500,600,700" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css?family=Istok+Web" rel="stylesheet">
    </head>
    <body>
        <app-root></app-root>
    </body>
</html>

我想根据所选语言从组件<html dir="ltr" lang="en">更新html元素中的dir和lang属性.

I want to update dir and lang attribute in html element from a component <html dir="ltr" lang="en"> based on the language selected.

在Angular中有没有办法解决这个问题?

Is there a way to go about this in Angular?

谢谢.

推荐答案

我认为,可以简单地对其进行更改...

I think, it can be changed simply...

https://stackblitz.com/edit/angular-ih2drk?file = src%2Fapp%2Fapp.component.ts

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

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  name = 'Angular 6';
  constructor(private renderer: Renderer2) {
    this.renderer.setAttribute(document.querySelector('html'), 'lang', 'tr');
  }
}

这篇关于Angular-更新根index.html中的html属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 03:12