2017-08-18 10 views
0

プロパティの子要素にアクセスする必要があります。アングル2親コンポーネントクラスの子コンポーネントオブジェクトにアクセスする

親:

<div> 
    <shipment-detail #myCarousel ></shipment-detail> 
</div> 

@Component({ 
    selector: "testProject", 
    templateUrl: "app/partials/Main.html") 
class AppComponent { 
    getChildrenProperty() { 
    // I want to get access to "shipment" 
    } 
} 

子供:

@Component({ 
     selector: "shipment-detail", 
    }) 
    export class ShipmentDetail { 
     shipment: Shipment; 
    } 
+2

anglejsの代わりにangleタグを編集する – Rahul

+0

**親コンポーネントからの[angle 2アクセスの子コンポーネントプロパティ]の正確な**複製(https://stackoverflow.com/questions/36628161/angular-2-access-child-親コンポーネントからのコンポーネントのプロパティ) – LarsMonty

+0

角度が更新され、私はそれを助けてくれなかったcommenと尋ねてみました。 –

答えて

1

@ViewChild@ViewChildrenデコレータは、子コンポーネントのクラスへのアクセスを提供します。

@Component({ 
    selector: "testProject", 
    templateUrl: "app/partials/Main.html") 
class AppComponent { 

    @ViewChild(ShipmentDetail) ShipDetails: ShipmentDetail; 

    getChildrenProperty() { 
     console.log(this.ShipDetails.shipment); 
    } 
} 

@ViewChildは、子コンポーネントの名前が必要ですクラスを入力として使用し、そのse親コンポーネントのlector。

あなたの場合はShipmentDetailである必要があります。

関連する問題