Accessing a parent component's ViewModel property from the child's ViewModel in Aurelia

Viewed 643

I have two components:

<parent-component type="permanent">
    <div child-component></div>
</parent-component>
class ParentComponentCustomElement {
    @bindable public type: string = "permanent";
}

class ChildComponentCustomAttribute {
    public attached() {
        // how to get the instance of ParentComponentCustomElement here?
    }
}

I need to access the type property of the parent to add some classes to the child-component conditionally.

I could probably traverse the parent tree through DOM and look for this specific component, but I don't think that's the correct way to do this.

2 Answers
Related