• About Morris Development
  • A Focus for Cloud Efficiency
    • Microsoft Azure
    • Amazon Web Services
  • What our Clients Say
  • Our Products
    • PreschoolDB
    • WebinarDB
  • Contact Us

Morris Development

Custom System Development and Integration

March 31, 2017

Triggering Events in a Child Component in Angular

Interactions between components has been more and more of a necessity.  In a component, we can easily bind functions and even send data back to the parent within this function (https://morrisdev.com/2016/08/angular-components-with-bound-functions-using-typescript/)However, triggering an event in the child by the parent is a big more convoluted.

 

You can see several options here http://stackoverflow.com/questions/37439300/communicating-events-from-parent-to-child-in-angularjs-components and they are all pretty convoluted.

The EASIEST way is not listed.  Essentially, all you need to do is have the child component wait for you to tell it what to do.  Components have a built in “$onChanges()” event that tracks the changes to a bound parameter (only a value, not an object with values changing within it).

So, if you have:


then your component can have a script like this:

public command:string;
public settings:any;

----  class object, constructor, etc... here   ----

$onChanges() {
            if(this.command=='refresh some data'){this.refreshData()}
            if(this.command=='DeleteRecord'){let id=this.settings.id;this.deleteRecord(id);}
            // and so forth  
        }

where your component declaration:


  app.component("mycomponent",
        {
            bindings: {
                settings: '<', command: '<'
            },
            templateUrl: 'yourtemplate.html,
            controller: ThisClassObject,
            controllerAs: 'vm'
        });
}

Basically, it's a "watch" and you can send it whatever you want. Rather than mess around trying to open links between states, just handle the events like this.

REMEMBER: It ONLY works with one-way binding, "<" not "=".

Article by MacGyver / AngularJS, Web Developer

About MacGyver

I've worked with database systems for over 20 years, and started my own company in 2000. Almost all my business consists of internal database systems, either ERP or CRM. My programming is primarily in Angular / Microsoft C# and MS SQL.

About This Site

Morris Development has been specializing in internal database system design and integration since 1999. We provide long-term management and support of secure data systems for many businesses as well as developing the more complex code structures for ERP systems like Intellievent, Apidas, and AVMS.

This site is primarily for our developers to keep track up various technologies and updates that are used by Morris Development.

Training

Integrating Angular Microsite with .Net

Private Data Caching with Google Storage

Continuous Deployment for Production Releases?

Azure Websites – the perfect Angular host

Angular 2

  • Angular 2 Authentication
  • Angular Command Line Interface
  • Material Design for Angular
  • Using Observables in Angular 2

Mentors

  • Ben Nadel
  • Dan Wahlin
  • Deborah Kurata
  • John Papa

Staff

  • Dan Morris

Training

  • Google Development Courses
  • Microsoft Virtual Academy
  • PluralSight
  • Test Deep Links

© 2025 · Morris Development