Créer une variable utilisable dans un service
Bonjour, tout d'abord je débute en Angular, RxJS, TS. Je cherche à utiliser une variable dans mon service, mais celle-ci a été crée dans mon modèle.
Je m'explique.
J'ai un BoxService qui est composé d'un modèle 'box.model.ts' composé de 3 paramètres :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
export class Box {
id: string;
thread: Thread;
discussion: Observable<Message[]>;
constructor(id?: string,
thread?: Thread,
discussion?: Observable<Message[]>) {
this.id = id || uuid();
this.thread = thread || null;
this.discussion = discussion || null;
}
} |
et d'un 'box.service.ts' :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
@Injectable()
export class BoxService {
windows: Box[];
currentBox: Subject<Box> =
new BehaviorSubject<Box>(new Box());
currentBoxMessages: Observable<Message[]>;
constructor(public messagesService: MessagesService) {
this.windows = [
];
this.currentBoxMessages = this.currentBox
.combineLatest(messagesService.messages,
(currentBox: Box, messages: Message[]) => {
if (currentBox && messages.length > 0) {
return _.chain(messages)
.filter( (message: Message) =>
(message.thread.id === currentBox.id))
.map( (message: Message) => {
message.isRead = true;
return message; })
.value();
} else {
return [];
}
});
};
addChatWindow(id?: string, thread?: Thread): Box {
const newBox: Box = new Box(id, thread);
this.windows.push(newBox);
return newBox;
}
setCurrentBox(newBox?: Box): void {
this.currentBox.next(newBox);
}
}
export const boxsServiceInjectables: Array<any> = [
BoxService
]; |
Je cherche à avoir la variable 'this.box.discussion' égale à la variable 'this.currentBoxMessages'.
Est ce que cela est possible ?
Merci d'avance car je sèche vraiment ..