Jay.Z
Jay.Z

Reputation: 67

Angular2/4 - Cannot read property subscribe of undefined

I am new to Angular and recently start to learn it by reading a book 'ng-book The Complete Book on Angular 4'. In the 'how angular works' chapter I wrote a small inventory app followed by the instructions on the book but having issue after startup, shown as below: error log on browser console

All my components seem alright and the errors are just not seem relevant to my code. I even compared to the example code downloaded and they look very identical.

I know it's probably not that much of a big deal and I should move on and go back to this when I gain more knowledge. But really it's bothering me...

Not sure what's the best way of showing all my source code here so I created a shareable google drive link and a .zip with everything in that project can be retrieved by the link. ANY HELP WILL BE HIGHLY APPRECIATED!!!

https://drive.google.com/file/d/0B76fFkACV6wRdmtJU0Jfc0J4U1U/view?usp=sharing

Upvotes: 5

Views: 2913

Answers (1)

Sherif Behna
Sherif Behna

Reputation: 613

In ProductsListComponent, you need to change :

@Output() onProductSelected: EventEmitter<Product>;

to :

@Output() onProductSelected = new EventEmitter<Product>();

Also, remove the line in ngOnInit in the same component.

The event emitter needs to be initialized when the class is created. See this example : http://learnangular2.com/outputs/

Upvotes: 10

Related Questions