Permalink
Browse files

Step 6.6: Add basic messages component

  • Loading branch information...
dotansimha authored and darkbasic committed Jan 24, 2017
1 parent b2c18fa commit 2e722f0c4592e138257a88508ccd3c87d892f3c7
Showing with 21 additions and 4 deletions.
  1. +21 −4 src/pages/messages/messages.ts
@@ -1,21 +1,38 @@
import { Component, OnInit } from '@angular/core';
import { NavParams } from 'ionic-angular';
import { Chat } from 'api/models';
import { Chat, Message } from 'api/models';
import { Observable } from 'rxjs';
import { Messages } from 'api/collections';
@Component({
selector: 'messages-page',
template: `Messages Page`
templateUrl: 'messages.html'
})
export class MessagesPage implements OnInit {
selectedChat: Chat;
title: string;
picture: string;
messages: Observable<Message[]>;
constructor(navParams: NavParams) {
this.selectedChat = <Chat>navParams.get('chat');
console.log('Selected chat is: ', this.selectedChat);
this.title = this.selectedChat.title;
this.picture = this.selectedChat.picture;
}
ngOnInit() {
let isEven = false;
this.messages = Messages.find(
{chatId: this.selectedChat._id},
{sort: {createdAt: 1}}
).map((messages: Message[]) => {
messages.forEach((message: Message) => {
message.ownership = isEven ? 'mine' : 'other';
isEven = !isEven;
});
return messages;
});
}
}

1 comment on commit 2e722f0

@sitexa

This comment has been minimized.

Show comment
Hide comment
@sitexa

sitexa Dec 1, 2017

From this step on , L26 this.messages = Messages.find(...) throws an exception:
Error:(47, 5) TS90010: Type 'Observable<Message[]>' is not assignable to type 'Observable<Message[]>'. Two different types with this name exist, but they are unrelated. Property 'source' is protected but type 'Observable<T>' is not a class derived from 'Observable<T>'.
There is a post on stackoverflow: Angular Type 'Observable<Message[]>' is not assignable to type 'Observable<Message[]>', but no valid answer.

How can I go through it?

sitexa commented on 2e722f0 Dec 1, 2017

From this step on , L26 this.messages = Messages.find(...) throws an exception:
Error:(47, 5) TS90010: Type 'Observable<Message[]>' is not assignable to type 'Observable<Message[]>'. Two different types with this name exist, but they are unrelated. Property 'source' is protected but type 'Observable<T>' is not a class derived from 'Observable<T>'.
There is a post on stackoverflow: Angular Type 'Observable<Message[]>' is not assignable to type 'Observable<Message[]>', but no valid answer.

How can I go through it?

Please sign in to comment.