import * as React from 'react'; import marked from 'marked'; export interface RealWorldComponentProps { [key: string]: any; } export interface RealWorldComponentState { [key: string]: any; } export interface Article { body: string; [key: string]: any; } class RealWorldComponent extends React.Component { protected article: Article; constructor( props: RealWorldComponentProps, context?: any /* article: Article, User, Comments, $sce, $rootScope */ ) { super(props, context); this.article = article; this._Comments = Comments; this.currentUser = User.current; $rootScope.setPageTitle(this.article.title); this.article.body = $sce.trustAsHtml(marked(this.article.body, {sanitize: true})); Comments.getAll(this.article.slug).then((comments) => (this.comments = comments)); this.resetCommentForm(); } private resetCommentForm() { this.commentForm = { isSubmitting: false, body: '', errors: [] }; } private addComment() { this.commentForm.isSubmitting = true; this._Comments.add(this.article.slug, this.commentForm.body).then( (comment) => { this.comments.unshift(comment); this.resetCommentForm(); }, (err) => { this.commentForm.isSubmitting = false; this.commentForm.errors = err.data.errors; } ); } private deleteComment(commentId, index) { this._Comments.destroy(commentId, this.article.slug).then((success) => { this.comments.splice(index, 1); }); } render() { return (
) => { event.keyCode == 13 && $ctrl.addTag(); }} />
{$ctrl.article.tagList.map((tag, index: number) => { return ( { $ctrl.removeTag(tag); }} /> {tag} ); })}
{lowercase($ctrl.appName)} © {date($ctrl.date, 'yyyy')}. An interactive learning project from{' '} Thinkster. Code licensed under MIT.
); } } export default RealWorldComponent;