Executing Angular 2 function in another component shows as undefined

I have two components:

1) sourceDisplayComponent 2) sourceDetailsComponent

My #2 component calls a function in #1, but it comes back as undefined. This is the line that gives the error:

ERROR TypeError: Cannot read property 'splice' of undefined

sources is an observable coming from an API and it is populated in #1 using:


array variable.

this.sourceDisplayService.getSources().subscribe(sources => {this.sources = sources;});

When I call the:

removeRow(index) {
      let numRows = this.sources.length;

Method from #2 such as:


It gives the above error. Where sdc is an instance of #1, I get the undefined error. Shouldn't the function be executed with the this.sources in memory so that it can remove the row from the datatable? Why can't I run that function and have it do what I want?