blacksonic/angular2-esnext-starter

View on GitHub
client/app/posts/components/post-new/post-new.component.js

Summary

Maintainability
A
1 hr
Test Coverage
import { Component } from '@angular/core';
import { Router } from '@angular/router';

import template from './post-new.template.html';
import { PostService } from '../../services/post/post.service';

@Component({
  selector: 'post-new',
  template: template
})
export class PostNewComponent {
  constructor(postService: PostService, router: Router) {
    this._postService = postService;
    this._router = router;
  }

  onSave(post) {
    this._postService.addPost(post).subscribe(
      () => {
        this._router.navigate(['']);
      },
      (error) => {
        console.error(error);
      }
    );
  }
}