i´m having problem with setting the reviews,
This is part of angular 2 project.
The line this.reviews = targ gives me
TypeError: Cannot set property 'reviews' of undefined
The targ seems to exist as i can print it into console succesfully.
Any ideas why this is happening?
import { ReviewService } from '../review.service';
import { Review } from '../review/review.component'
import { Component} from '@angular/core';
import { OnInit } from '@angular/core';
@Component({
selector: 'review-list',
templateUrl: './review-list.component.html',
styleUrls: ['./review-list.component.css'],
providers: [ReviewService] //for the injector to be able to inject ReviewerService
})
export class ReviewListComponent implements OnInit {
public reviews: Review[];
constructor(private reviewService: ReviewService) {
this.reviews = [] ;
}
initializeReviews(): void {
this.reviewService.getReviews().then(
this.set
).catch(function(reason){
console.log(reason);
});
}
set(targ):void {
console.log(targ);
this.reviews = targ;
}
ngOnInit(): void {
this.initializeReviews();
//this.reviews = this.reviewService.get();
}
}