I have an issue with ngonchanges not firing.
I have this component:
@Component({
selector: 'conversation-detail',
templateUrl: './conversation-detail.component.html'
})
export class ConversationDetailComponent implements OnChanges{
@Input()
selectedConversation: Conversation;
title = 'Conversation Detail';
convoMessages: Array<Message> = [];
constructor(
private _messageService: MessageService
){};
ngOnChanges(changes: SimpleChanges){
this.getMessages();
}
ngOnInit(): void{
}
private getMessages(){
if(this.selectedConversation != undefined){
this._messageService.getMessagesForConversation(this.selectedConversation.ConversationId).then(
data => {
if (data) {
this.convoMessages = data.serviceResult as Array<Message>;
} else {
//This really should never happen
console.error('Error retrieving users data: Data object is empty');
}
},
error => {
//loader.dismiss();
console.error('Error retrieving users data');
console.dir(error);
}
);
}
}
}
The ngonchanges will fire the first time selectedConversation changes. GetMessages is called and it loads in the message data. After that ngonchanges no longer fires when selectedConversation changes.
If I comment out the function call to getMessages then ngonchanges will fire every time selectedConversation changes.
so, I'm not sure what is going on in getMessages that cuts off ngonchanges from firing off. The request returns data and the call ends. Anyone have any ideas?