1
我對angular 2相當陌生,並且堅持一個基本問題。angular 2如何將服務響應數據傳遞給UI
顯示的UI我的組件是這樣的: chat.ts
@IonicPage()
@Component({
selector: 'page-chat',
templateUrl: 'chat.html',
providers: [ChatService]
})
export class ChatPage {
items: SimpleMessage[] = [];
createChatBubble(chatMessage: string){
//alert(this.chatMessage);
this.items.push(new SimpleMessage(chatMessage));
}
}
聊天service.ts
@Injectable()
export class ChatService {
openSocket(){
this.ws = new WebSocket('ws://' + this.host + '/chat/ws');
this.ws.addEventListener('message', event => {
this.zone.run(() => {
var msg = JSON.parse(event.data);
this.broadcast(msg);
});
});
broadcast(msg){
let message = this.parseModel(msg);
let chatReply = new SimpleMessage(message, 'bot');
}
}
所以,從服務器中broadbast功能需求收到消息以某種方式傳遞給chat.ts項目對象。請告知
都需要componentChangeSource和newDateCreationSource還是隻需要兩個不同的變體? – Vik
只是不同的變化,顯示不一定需要傳遞一些數據。 – LLL
其中componentChanged $在服務中聲明?這到底意味着什麼? – Vik