本文整理汇总了TypeScript中@angular/core.ComponentRef.onDestroy方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ComponentRef.onDestroy方法的具体用法?TypeScript ComponentRef.onDestroy怎么用?TypeScript ComponentRef.onDestroy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/core.ComponentRef
的用法示例。
在下文中一共展示了ComponentRef.onDestroy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: load
// Load an instance of ComponentRef in app view.
load(componentRef: ComponentRef<any>) {
const rootElement = componentRef.location.nativeElement;
if (this.appRef['attachView']) {
// angular2.3.x has `attachView` and `detachView` methods.
this.appRef['attachView'](componentRef.hostView);
componentRef.onDestroy(() => {
this.appRef['detachView'](componentRef.hostView);
if (rootElement.parentNode) {
rootElement.parentNode.removeChild(rootElement);
}
});
} else {
if (this.appRef['registerChangeDetector']) {
this.appRef['registerChangeDetector'](componentRef.changeDetectorRef);
}
componentRef.onDestroy(() => {
if (this.appRef['unregisterChangeDetector']) {
this.appRef['unregisterChangeDetector'](componentRef.changeDetectorRef);
}
if (rootElement.parentNode) {
rootElement.parentNode.removeChild(rootElement);
}
});
}
const rootContainer = this.appRef['_rootComponents'][0].location.nativeElement;
rootContainer.appendChild(rootElement);
}
示例2: connect
connect(attrs?: WormholeAttributes, events?: string[], index?: number): Observable<WormholeEvent> {
if (typeof attrs === 'object' && attrs) {
this.cachedAttrs = attrs;
}
this.disconnect();
this.compRef = this.attach(this.componentClass, index);
this.compRef.onDestroy(() => {
this.compRef = undefined;
});
const instance = this.compRef.instance;
if (this.cachedAttrs && typeof this.cachedAttrs === 'object') {
Object.assign(instance, this.cachedAttrs);
}
this.compRef.changeDetectorRef.detectChanges();
const events$ = (events || []).map(event => {
if (!instance[event]) {
throw new Error('Event not found: ' + event);
}
return instance[event] && instance[event].pipe( map(value => ({type: event, value})) );
});
return merge(...events$);
}