如何解决输出指令-按上下文绑定
我想使用source 'https://cocoapods-cdn.netlify.app/'
,但是在这样的非标准场景中,我不能使用角度语法@Output()
,但是我必须这样绑定到上下文:
(somethingChanged)="console.log($event)"
所以我的子组件看起来像:
<nb-icon
[nbPopover]="messagesComponent"
[nbPopoverContext]="{ messages: downloadedMessages,onLoadMoreMessages: ??????}"
>
</nb-icon>
我该怎么做?
解决方法
您可以传递任何内容作为输入,例如整个父组件...虽然有点奇怪,所以传递一些包装器(例如,在角形材质中使用类似的方法:将FormControl传递给输入):
class MyWrapper {
subject = new Subject();
emit() {
this.subject.next();
}
}
在父母中:
this.onLoadHandler = new MyWrapper();
this.onLodaHandler.subject.subscribe(() => ...)
<nb-icon
[nbPopover]="messagesComponent"
[nbPopoverContext]="{ messages: downloadedMessages,onLoadHandler: onLoadHandler}"
>
</nb-icon>
在孩子中,您有:
someMethod() {
...
this.onLoadHandler.emit(...);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。