相关疑难解决方法(0)

如何使用/创建动态模板来使用Angular 2.0编译动态组件?

我想动态创建模板.这应该用于ComponentType运行时构建一个并在托管组件内部放置(甚至替换)它.

直到我使用RC4 ComponentResolver,但RC5我收到消息:

ComponentResolver不推荐用于动态编译.使用ComponentFactoryResolver连同@NgModule/@Component.entryComponents或ANALYZE_FOR_ENTRY_COMPONENTS提供商,而不是.对于仅运行时编译,您也可以使用Compiler.compileComponentSync/Async.

我发现了这个(官方的angular2)文件

Angular 2同步动态组件创建

并了解我可以使用其中之一

  • 一种动态的ngIfComponentFactoryResolver.如果我将已知组件传递到托管内部@Component({entryComponents: [comp1, comp2], ...})- 我可以使用.resolveComponentFactory(componentToRender);
  • 真正的运行时编译,带Compiler...

但问题是如何使用它Compiler?上面的注释说我应该打电话:Compiler.compileComponentSync/Async- 那怎么样?

例如.我想为一种设置创建(基于一些配置条件)这种模板

<form>
   <string-editor
     [propertyName]="'code'"
     [entity]="entity"
   ></string-editor>
   <string-editor
     [propertyName]="'description'"
     [entity]="entity"
   ></string-editor>
   ...
Run Code Online (Sandbox Code Playgroud)

在另一种情况下这个(string-editor被替换text-editor)

<form>
   <text-editor
     [propertyName]="'code'"
     [entity]="entity"
   ></text-editor>
   ...
Run Code Online (Sandbox Code Playgroud)

等等(editors属性类型的不同数量/日期/引用,跳过一些用户的某些属性......).即这是一个例子,真正的配置可以生成更多不同和复杂的模板.

该 …

compilation typescript angular2-compiler angular

185
推荐指数
10
解决办法
13万
查看次数

angular-cli build prod"未加载运行时编译器"

我做了构建-prod并遇到了一个奇怪的错误,即_zone_symbol__error:

Error: Uncaught (in promise): Error: Runtime compiler is not loaded Error: Runtime compiler is not loaded at d (http://localhost:4200/polyfills.cd321326a3dfc08ceb46.bund
Run Code Online (Sandbox Code Playgroud)

我没有在我的应用程序中手动使用编译器.最奇怪的是错误似乎来自polyfill.我怎么解决这个问题?

angular-cli angular

12
推荐指数
3
解决办法
1万
查看次数

在没有延迟加载的情况下路由到子路由模块

我想拥有多个routing模块,以保持我的应用程序清洁和易于阅读.我目前使用延迟加载,SubComponent但我不想这样做.所以我正在寻找一种方法来改变它.无论如何,这是目前正在运行的代码.

我有以下两个路由文件.

app-routing.module.ts:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [
  { path: '', component: HomeComponent },
  { path: 'sub', loadChildren: './sub/sub.module#SubModule' }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
Run Code Online (Sandbox Code Playgroud)

sub-routing.module.ts:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [
  { path: '', component: SubComponent, children: [
    { path: 'new', component: SubEditComponent }
  ] }, …
Run Code Online (Sandbox Code Playgroud)

routing router lazy-loading angular-routing angular

7
推荐指数
2
解决办法
3488
查看次数