Today, We want to share with you Angular Call Component function into another component.In this post we will show you angular parent call child function, hear for angular call function from sibling component we will give you demo and example for implement.In this post, we will learn about typescript call function from another component with an example.
Angular Call Component function into another component
There are the Following The simple About angular 4 call method in another component Full Information With Example and source code.
As I will cover this Post with live Working example to develop ionic 4 call function from another page, so the how to call another component function in angular2 is used for this example is following below.
Angular is a platform for building mobile & desktop web Based user friendly and light weight applications.Angular,It’s TypeScript-based open-source Angularjs web application framework.
how to call another component function in angular?
src/app/app.module.ts
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { AppComponent } from './app.component'; import { NewAppFirstComponent } from './compOne.component'; import { NewAppSecondComponent } from './compTwo.component'; @NgModule({ imports: [ BrowserModule, FormsModule ], declarations: [ AppComponent, NewAppFirstComponent, NewAppSecondComponent ], bootstrap: [ AppComponent ] }) export class AppModule { }
src/app/compOne.component.ts
import { Component, OnInit } from '@angular/core'; @Component({ selector: 'live-angu-application', template: ``, }) export class NewAppFirstComponent implements OnInit { constructor() { } ngOnInit() { } getProductsList(){ console.log('get All Products Data Funcrion/methods from Angularjs Component'); } }get All Funcrion/methods Component
src/app/compTwo.component.ts
import { Component, OnInit } from '@angular/core'; @Component({ selector: 'live-angu-application-second', template: ``, }) export class NewAppSecondComponent implements OnInit { constructor() { } ngOnInit() { } }Call Component Two
Output:
get All Products Data Funcrion/methods from Angularjs Component get All Products Data Funcrion/methods from Angularjs Component get All Products Data Funcrion/methods from Angularjs Component get All Products Data Funcrion/methods from Angularjs Component
Angular call component method from another component
src/app/compTwo.component.ts
import { Component, OnInit } from '@angular/core'; import { NewAppFirstComponent } from './compOne.component'; @Component({ selector: 'live-angu-application-second', template: ``, }) export class NewAppSecondComponent implements OnInit { constructor() { } ngOnInit() { let myCompOneObj = new NewAppFirstComponent(); myCompOneObj.getProductsList(); } }Call Component Two
Output:
get All Products Data Funcrion/methods from Angularjs Component
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about shared function angular.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.