Skip to main content

Posts

Showing posts with the label Communicate between components Angular 2

How do Components Communicate with Each Other in Angular 2?

In Angular 1 , I have some ways to communicate between controllers i.e. 1.       $rootScope, 2.       $scope, 3.       $emit, 4.       $broadcast Now In Angular 2 , we have different ways to communicate between components. A parent component and its children share a service whose interface enables bi-directional communication within the family. Stayed Informed   - Angular2 Components Life-cycle The following examples for Services communication, import {Injectable} from '@angular/core' ; @ Injectable() export class MyService { constructor () { } } import { Component } from '@angular/core' ; @ Component({ selector : 'my-app' , templateUrl : './myApp.component.html' }) export class MyAppComponent { } The following example to calling service from any other component, import {Component, OnInit} from '@angular/core' ; import ...