3

Need to access to property children element.

Parent:

<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" 
  }
}

Children:

@Component({
      selector: "shipment-detail",
    }) 
    export class ShipmentDetail  {
      shipment: Shipment;
    }
3
  • 2
    Edit tag to angular instead of angularjs Commented Aug 18, 2017 at 17:33
  • Exact duplicate of angular 2 access child component property from parent component Commented Aug 18, 2017 at 18:53
  • The answer over there does not work anymore as angular is updated and i tried to ask it with a commen which didnt help.. Commented Aug 18, 2017 at 20:04

1 Answer 1

4

The @ViewChild and @ViewChildren decorators provide access to the class of child component:

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

    @ViewChild(ShipmentDetail) ShipDetails: ShipmentDetail;

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

@ViewChild requires the name of child component class as its input and finds its selector in the parent component.

In your case it should be ShipmentDetail.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.