【发布时间】:2021-11-06 02:52:26
【问题描述】:
我想支持以下微语法:
foo$ | async as xyz
例子:
<p *appVar="foo$ | async as xyz">
Value is {{ xyz }}!
</p>
该流被定义为
$foo = of('some value')
这是我的指令:
@Directive({
selector: '[appVar]'
})
export class VarDirective<T> {
@Input() appVar: T;
constructor(
private templateRef: TemplateRef<T>,
private viewContainer: ViewContainerRef
) {}
ngOnInit(): void {
this.viewContainer.createEmbeddedView(this.templateRef);
}
}
现在,无论我做什么,xyz 变量始终是未定义的。
如果我创建一个上下文(在this 帖子中建议)
const context = { $implicit: this.appVar };
this.viewContainer.createEmbeddedView(this.templateRef, context);
我得到相同的结果。有什么建议我在这里做错了吗?
【问题讨论】:
-
试试
(foo$ | async) as xyz -
不,同样的结果
标签: angular angular-structural-directive