修改根组件以外的DOM元素 [英] Modify DOM elements outside root component

查看:179
本文介绍了修改根组件以外的DOM元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的角2的应用程序的结构是这样的:

My Angular 2 app is structured something like this:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <base href="/" />

    <script src="jspm_packages/system.js"></script>
    <script src="config.js"></script>

    <script>
        System.import('client/main.js');
    </script>
</head>
<body>
    <my-app></my-app>
</body>
</html>

根组件是我的应用部分。

我想修改 HTML 元素,它的根组件模板外一些属性添加到它。这可能吗?

I would like to modify the html element which is outside the root component template to add some attributes to it. Is this possible?

在我的情况,我想设置 DIR 根据当前用户的设置的属性,这将在运行时进行检索。

In my case, I'm trying to set dir and lang attributes based on the current user's settings, which would be retrieved at runtime.

推荐答案

您可以使用普通的 JS访问DOM 或使用如标题服务的https://github.com/angular/angular/blob/master/modules/angular2/src/platform/browser/title.ts

You can either use normal JS DOM access or use the DOM adapter as shown in the Title service https://github.com/angular/angular/blob/master/modules/angular2/src/platform/browser/title.ts

这篇关于修改根组件以外的DOM元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆