简体   繁体   中英

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.

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

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) {
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM