Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { FormGroup, FormBuilder, Validators } from '@angular/forms';
- import { PostService } from 'src/app/core/services/post.service';
- import { Router, ActivatedRoute } from '@angular/router';
- import { Post} from '../../shared/models/post.model';
- @Component({
- selector: 'app-post-edit',
- templateUrl: './post-edit.component.html',
- styleUrls: ['./post-edit.component.css']
- })
- export class PostEditComponent implements OnInit {
- postEditForm: FormGroup;
- post: Post;
- constructor(private fb: FormBuilder, private postService: PostService, private router: Router, private route: ActivatedRoute,) { }
- ngOnInit() {
- this.postEditForm = this.fb.group({
- title: [ '', [Validators.required, Validators.minLength(3), Validators.maxLength(23)]],
- author: [ '', [Validators.required, Validators.minLength(3), Validators.maxLength(23)]],
- content: [ '', [Validators.required, Validators.minLength(200), Validators.maxLength(5000)]],
- image: [ '', [Validators.required]]
- })
- }
- get title() { return this.postEditForm.get('title'); }
- get author() { return this.postEditForm.get('author'); }
- get content() { return this.postEditForm.get('content'); }
- get image() { return this.postEditForm.get('image'); }
- editPost() {
- const valueForm = this.postEditForm.value;
- const id = this.route.snapshot.paramMap.get('id');
- this.postService.editPost(valueForm, id).subscribe((data) => {
- this.router.navigate(['/posts']);
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement