我想手动编译一些包含HTML的指令.$compileAngular 2中的等价物是什么?
例如,在Angular 1中,我可以动态编译HTML片段并将其附加到DOM:
var e = angular.element('<div directive></div>');
element.append(e);
$compile(e)($scope);
Run Code Online (Sandbox Code Playgroud) 我在Angular 2模板中遇到了一个奇怪的赋值语法.
<template let-col let-car="rowData" pTemplate="body">
<span [style.color]="car[col.field]">{{car[col.field]}}</span>
</template>
Run Code Online (Sandbox Code Playgroud)
看来,let-col和let-car="rowData"创建两个新的变量col和car,然后可以绑定到模板中.
资料来源:https://www.primefaces.org/primeng/#/datatable/templating
这个神奇的let-*语法叫什么?
它是如何工作的?
let-something和之间有什么区别let-something="something else"?
可以使用let-col而不是在let-car="rowData"不更改最终DOM结构的情况下重写上述代码吗?
我正在使用具有动态值的ngTemplateOutlet.
<ng-container *ngFor="let part of objectKeys(config);">
<ng-container *ngIf="config[part]">
<ng-container [ngTemplateOutlet]="part"></ng-container>
</ng-container>
</ng-container>
<ng-template #one></ng-template>
<ng-template #two></ng-template>
Run Code Online (Sandbox Code Playgroud)
config对象在哪里config[part]布尔值在哪里part是目标的关键,并传递给ngTemplateOutlet值.我总是得到错误:
ERROR TypeError: templateRef.createEmbeddedView is not a function
Run Code Online (Sandbox Code Playgroud)
我跟着:https://stackoverflow.com/a/41241329/5627096
但也许我不能做那样的事情.
实际上,配置对象包含布尔值,就像我说的那样,并定义要显示的表单部分.
这是一个非常大的形式,为了更好的阅读,我正在寻找一个分裂它的解决方案.
UPDATE
config对象看起来像:
config = {
one: true,
two: false
}
Run Code Online (Sandbox Code Playgroud)
所以在我的表单中只<ng-template #one></ng-template>显示了.如果我将两个转为true,则显示两者.
我不知道这是不是最好的方法.我可以使用*ngIf,但是使用这个解决方案,我真的无法读取大代码.