Skip to content

Instantly share code, notes, and snippets.

@nerdic-coder
Created April 30, 2018 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerdic-coder/528e7b607158b0812b42907080ce086f to your computer and use it in GitHub Desktop.
Save nerdic-coder/528e7b607158b0812b42907080ce086f to your computer and use it in GitHub Desktop.
messages.tsx
import { Component, State } from '@stencil/core';
import { MessageService } from '../../services/message.service';
@Component({
tag: 'app-messages',
styleUrl: 'messages.css'
})
export class Messages {
private messageService: MessageService;
@State() private messages: string[];
constructor() {
this.messageService = MessageService.Instance;
}
componentWillLoad() {
this.getMessages();
}
getMessages(): void {
this.messageService.getMessages()
.subscribe(messages => {
this.messages = [];
this.messages = messages;
});
}
render() {
return (
<div class='app-messages'>
Messages:
{this.messages ?
(
<button class="clear"
onClick={() => this.messageService.clear()}>clear</button>
) : ( null )
}
{this.messages ?
(
this.messages.map((message) =>
<p>{message}</p>
)
) : ( null )
}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment