Angular组件有装饰器:
@Component({ ... })
export class MyAngularComponent {
@Input() myInputParam: MyType;
@Input() myOtherInputParam: MyOtherType;
@Output() myOutputParam: MyOtherOutputType;
}
Run Code Online (Sandbox Code Playgroud)
我有一个Angular库,如果我能以编程方式检索@Input()给定组件类(虽然属于库)中的 Angular的装饰器,可以避免很多代码重复(并减少bundle大小).
但我怀疑这种实现的可移植性.我已经读过某个地方,如果Angular应用程序是在启用了AoT的情况下构建的(并且只使用了Angular装饰器),则不需要Reflect polyfill(在运行时读取装饰器所需).所以我认为我不能只使用Reflect.*.Angular如何存储装饰器?是否有可靠,面向未来的方式来阅读它们?
缩小应该不是问题,因为它只用于读取库组件的装饰器,所以我可以控制它.
所以,如果这是可行的方式(或者不是,我仍然感兴趣),我怎么能读取那些装饰器?
angular-decorator angular2-decorators angular-compiler-cli angular
我想知道context参数createEmbeddedView()在 Angular 方法中的作用是什么。在线角度文档不提供此信息。
例如,我正在阅读此代码,其中作者制作了一个迭代器结构指令。
import {
Directive, ViewContainerRef, TemplateRef, Input, SimpleChange
} from "@angular/core";
@Directive({
selector: "[paForOf]"
})
export class PaIteratorDirective {
constructor(private container: ViewContainerRef, private template: TemplateRef<Object>) {
}
@Input("paForOf") dataSource: any;
ngOnInit() {
this.container.clear();
for (let i = 0; i < this.dataSource.length; i++) {
this.container.createEmbeddedView(this.template, new PaIteratorContext(this.dataSource[i]));
}
}
}
class PaIteratorContext {
constructor(public $implicit: any) { }
}
Run Code Online (Sandbox Code Playgroud)
这显示在模板上的复选框选中事件中,如下所示:
<div class="checkbox">
<label><input type="checkbox" [(ngModel)]="showTable" />Show Table</label>
</div>
<table *paIf="showTable" class="table table-sm table-bordered table-striped"> …Run Code Online (Sandbox Code Playgroud)