I'm learning Angular, I have these components:
MainComponent.ts
import {Component} from 'angular2/core';
import {UsersTableComponent} from './UsersTableComponent';
import {UserAddComponent} from './UserAddComponent';
@Component({
selector: 'main',
templateUrl: '../app/views/mainView.html',
directives: [UsersTableComponent, UserAddComponent]
})
export class MainComponent {
constructor() {}
}
UserAddComponent.ts
import {Component} from 'angular2/core';
import {GenderPipe} from '../pipes/GenderPipe';
@Component({
selector: 'userAdd',
templateUrl: '../app/views/userAdd.html',
pipes: [GenderPipe]
})
export class UserAddComponent {
constructor() {}
addUser() {
alert(1);
}
}
UserTableComponent
import {Component} from 'angular2/core';
import {UserServices} from '../services/UserServices';
import {User} from '../classes/User';
import {GenderPipe} from '../pipes/GenderPipe';
@Component({
selector: 'usersTable',
templateUrl: '../app/views/usersTable.html',
pipes: [GenderPipe]
})
export class UsersTableComponent {
users: Array<User>
constructor(UserServices: UserServices) {
this.users = UserServices.getUsers();
}
}
on the UserAddComponent on addUser method I need to read some values from the template and update users though UserServices. When it is updated, I need to call a method from the UserTableComponent in order to refresh a table with the data added to the users.
How can I call a method in one component from another component?