angular2-compiler

Dynamically load HTML template in angular2

社会主义新天地 提交于 2019-11-26 09:07:57
问题 I have created a project using angular-cli which contains AppComponent as follows: import { Component } from \'@angular/core\'; @Component({ selector: \'app-root\', templateUrl: \'./app.component.html\', styleUrls: [\'./app.component.css\'] }) export class AppComponent { title = \'app works!\'; } And app.component.html as <h1> Good Morning, {{title}} </h1> So when I build it with ng build it generates some files like this ./dist/main.bundle.js which contents some code as follows- /* 586 */ /*

Equivalent of $compile in Angular 2

一曲冷凌霜 提交于 2019-11-25 22:17:29
问题 I want to manually compile some HTML containing directives. What is the equivalent of $compile in Angular 2? For example, in Angular 1, I could dynamically compile a fragment of HTML and append it to the DOM: var e = angular.element(\'<div directive></div>\'); element.append(e); $compile(e)($scope); 回答1: Angular 2.3.0 (2016-12-07) To get all the details check: How can I use/create dynamic template to compile dynamic Component with Angular 2.0? To see that in action: observe a working plunker

How can I use/create dynamic template to compile dynamic Component with Angular 2.0?

狂风中的少年 提交于 2019-11-25 21:41:14
问题 I want to dynamically create template . This should be used to build a ComponentType at Runtime and place (even replace) it somewhere inside of the hosting Component. Until RC4 I was using ComponentResolver , but with RC5 I get message: ComponentResolver is deprecated for dynamic compilation. Use ComponentFactoryResolver together with @NgModule/@Component.entryComponents or ANALYZE_FOR_ENTRY_COMPONENTS provider instead. For runtime compile only , you can also use Compiler.compileComponentSync