2017-04-05 48 views
0

有沒有可能查詢由Viewchild裝飾的對象的DOM,就像我會用jQuery一樣?對jQuery做類似於用viewChild裝飾的對象的操作

我必須做下面的東西給孩子的DOM。

@ViewChild('someComponent') child: SomeComponent; 

    ngAfterViewInit() { 
    this.child.queryTheDomElementFor('some tag'); 
    this.child.getDomElementThatContains('specific Content'); 
    this.child.setCss(this.child.someNode, 'css rules'); 
    } 

回答

0

是的,它是可能的,

@ViewChild('someComponent') someComponent: SomeComponent; 

    ngAfterViewInit() { 
    document.querySelectorAll(..); 
    document.getElementById(..); 
    document.getElementByClass(..); 
// also nativeElement property can be used as 
    this.someComponent.nativeElement.children 
    } 

<element #someComponent> </element> 

更新:

您可以使用組件的方法,你已經宣佈它作爲viewChild作爲

this.someComponent.someMethod() 
+0

SomeComponent類沒有那些jQuery方法。 – Lev

+0

哪個jQuery方法?哪些組件 – Aravind

+0

SomeComponent類沒有方法querySelectorAll等 – Lev