子指令中的父元素引用

时间:2016-10-21 09:03:17

标签: angular components

如何在子指令Angular 2中获取父引用。?

export class ParentComponent<W, T> {
public tags: Array<any>;
public model: T = <T>{};
public widget: W;
protected outputs: Array<string>;
protected twoways: Array<string>;

constructor(protected name: string, protected el: ElementRef, protected cdRef: ChangeDetectorRef) {        
}
}

export function CreateComponent(name: string, componentArgs: {
selector: string,
inputs: Array<string>,
outputs: Array<string>,
directives?: any, 
template: string,
changeDetection?: any,
queries: {
    [key: string]: any
}
}, args): Type<any> {
componentArgs.changeDetection = ChangeDetectionStrategy.OnPush;  

var comp = Component(componentArgs);
return comp.Class({
    extends: ParentComponent,
    constructor: [ElementRef, ChangeDetectorRef, function (el: ElementRef, cdRef: ChangeDetectorRef) {
        this.tags = args.tags;
        this.outputs = componentArgs.outputs;
        this.twoways = args.twoways;
        ParentComponent.call(this, name, el, cdRef);
    }]
})
}


 @Directive({
selector: '[j-template]'     
})


export class JTemplateDirective{   
@Input() widget; 
private childViews : any = [];
constructor(protected el: ElementRef, protected viewContainerRef: ViewContainerRef,
    protected templateRef: TemplateRef<any>, @Host() @Inject(forwardRef(() => EJComponents)) display: EJComponents<any, any>) {

}

ngOnInit(){
}

ngAfterViewInit(){
}
}

在上面的j-template指令中,如何获取ParentComponet引用并访问属性。?

0 个答案:

没有答案