我们可以用户Rendered2
在 Angular 应用程序的浏览器版本中,但它需要document.body
参考,它在服务器渲染上不可用。
platform-browser
has Title
and Meta
组件,但我想有更多的控制权<head>
部分,如注射<script>
标签,访问body
元素等
有办法做到吗?
实际上,Angular Universal 使用DOMINO https://github.com/fgnass/domino引擎盖下的图书馆,它创建了document
与浏览器的方式相同。唯一的区别是你必须注入DOCUMENT
像这样:
import { DOCUMENT } from '@angular/common';
import { Component, Inject, Renderer2 } from '@angular/core';
@Component({ ... })
export class AppComponent {
constructor(@Inject(DOCUMENT) document, r: Renderer2) {
r.addClass(document.body, 'myclass');
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)