adeelmahmood
adeelmahmood

Reputation: 2431

angular2 relationship between @Component and Class

How is the relationship between a component controller class and the component is formed. Is it simply based on the positioning that whatever class comes after a given component, it becomes the component controller class for the component defined before it. How does it works if you have multiple components in a single js file. How do you associate a class anywhere in the js file to a component.

Along the same lines, is there such a thing as child components and in that case do these child components inherit something from parent components and more specifically from the component controller class of parent component.

Upvotes: 3

Views: 1471

Answers (2)

kakaja
kakaja

Reputation: 734

There are some kind of parents which are declared in the class constructor. Here is an example http://victorsavkin.com/post/118372404541/the-core-concepts-of-angular-2:

class Component {
    constructor(sibling:SiblingCmp,
          @Parent parent:ParentCmp,
          @Ancestor ancestor:AncestorCmp) {
    }
}

Upvotes: 0

basarat
basarat

Reputation: 275927

How is the relationship between a component controller class and the component is formed. Is it simply based on the positioning that whatever class comes after a given component, it becomes the component controller class for the component defined before it.

Yes.

How does it works if you have multiple components in a single js file

Have the structure:

@Component ...
class Foo ...

@Component ...
class Bar ...

Is there such a thing as child components and in that case do these child components inherit something from parent components and more specifically from the component controller class of parent component.

Components don't inherit. Components compose. Search inheritance vs. composition (but I sure you know this).

Also see : https://github.com/Microsoft/TypeScript/issues/2249

Upvotes: 3

Related Questions