本文整理汇总了TypeScript中@angular/core.RendererFactory2类的典型用法代码示例。如果您正苦于以下问题:TypeScript RendererFactory2类的具体用法?TypeScript RendererFactory2怎么用?TypeScript RendererFactory2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RendererFactory2类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: addInlineCodeToDocument
export function addInlineCodeToDocument(inlineCode: string, doc: Document, rendererFactory: RendererFactory2) {
const renderType: RendererType2 = { id: '-1', encapsulation: ViewEncapsulation.None, styles: [], data: {} };
const renderer = rendererFactory.createRenderer(doc, renderType);
const script = renderer.createElement('script');
renderer.setValue(script, inlineCode);
renderer.insertBefore(doc.head, script, doc.head.firstChild);
}
示例2: constructor
constructor(
private componentFactoryResolver: ComponentFactoryResolver,
private appRef: ApplicationRef,
private injector: Injector,
rendererFactory: RendererFactory2,
) {
this.renderer = rendererFactory.createRenderer(null, null);
}
示例3: constructor
/**
* Constructor
* @param rendererFactory
*/
constructor(private rendererFactory: RendererFactory2) {
this.renderer = rendererFactory.createRenderer(null, null);
}
示例4: Error
/**
* Inject the State into the bottom of the <head>
*/
inject() {
try {
const document: any = this.state.getDocument();
const transferStateString = JSON.stringify(this.toJson());
const renderer = this.rendererFactory.createRenderer(document, {
id: '-1',
encapsulation: ViewEncapsulation.None,
styles: [],
data: {}
});
const head = document.head;
if (head.localName !== 'head') {
throw new Error(
'Please have <head> as the first element in your document'
);
}
const script = renderer.createElement('script');
renderer.setValue(
script,
`window['TRANSFER_STATE'] = ${transferStateString}`
);
renderer.appendChild(head, script);
} catch (e) {
console.error(e);
}
}
示例5: inject
/**
* Inject the State into the bottom of the <head>
*/
inject() {
try {
const document: any = this.state.getDocument();
const transferStateString = JSON.stringify(this.toJson());
const renderer = this.rendererFactory.createRenderer(document, {
id: '-1',
encapsulation: ViewEncapsulation.None,
styles: [],
data: {}
});
const body = document.body;
const script = renderer.createElement('script');
renderer.setValue(script, `window['TRANSFER_STATE'] = ${transferStateString}`);
renderer.appendChild(body, script);
} catch (e) {
console.log('Failed to append TRANSFER_STATE to body');
console.error(e);
}
}
示例6: createRenderer
private createRenderer(el: any, type: RendererType2, id: number) {
this._renderStore.store(this._rendererFactory.createRenderer(el, type), id);
}