Answer the question
In order to leave comments, you need to log in
How to pass data from one component to another in Angular2?
Hello!
I'm trying the second version of Angular.
Question about inheritance, is there a main component to display the template
export class App {
name = 'Angular 2 Webpack Starter';
url = 'https://twitter.com/AngularClass';
guest = true;
constructor() {
}
isGuest(login) {
return this.guest = login;
}
}
class About extends App {}
Answer the question
In order to leave comments, you need to log in
can be passed in a service that is defined in the parent component.
//parent
@Component({
//...
providers: [SharedDataService]
//...
})
In the first Angular, this was done through directive controllers or services.
In the second, through services or hierarchical Dependency Injection - you can send the necessary data from the parent component to the child component, look for the dock on the offsite
Create a service, make it @Injectable
.
Further, it should be clear. :)
Try the construct:
import {название_родительского_компонента} from './родительский_компонент';
...
@Component({
...
directives: [название_родительского_компонента]
})
I tried it through a directive, I got: Unexpected directive value 'undefined' on the View of component.
Tried via @Injectable , works but doesn't inherit, changing property in parent, property with child component doesn't change.. doing something wrong
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question