本文整理匯總了TypeScript中@angular/core.RendererFactory2.createRenderer方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript RendererFactory2.createRenderer方法的具體用法?TypeScript RendererFactory2.createRenderer怎麽用?TypeScript RendererFactory2.createRenderer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@angular/core.RendererFactory2
的用法示例。
在下文中一共展示了RendererFactory2.createRenderer方法的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: 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 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);
}
}
示例3: constructor
constructor(
private componentFactoryResolver: ComponentFactoryResolver,
private appRef: ApplicationRef,
private injector: Injector,
rendererFactory: RendererFactory2,
) {
this.renderer = rendererFactory.createRenderer(null, null);
}
示例4: 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);
}
}
示例5: createRenderer
private createRenderer(el: any, type: RendererType2, id: number) {
this._renderStore.store(this._rendererFactory.createRenderer(el, type), id);
}
示例6: constructor
/**
* Constructor
* @param rendererFactory
*/
constructor(private rendererFactory: RendererFactory2) {
this.renderer = rendererFactory.createRenderer(null, null);
}