33 lines
877 B
TypeScript
33 lines
877 B
TypeScript
import { Component, effect, inject, signal } from '@angular/core';
|
|
import { PostEditorComponent } from '../../../components/post-editor/post-editor.component';
|
|
import { Post } from '../../../shared/interfaces/post';
|
|
import { PostsService } from '../../../shared/services/posts.service';
|
|
import { Location } from '@angular/common';
|
|
|
|
@Component({
|
|
selector: 'app-create-post',
|
|
imports: [PostEditorComponent],
|
|
templateUrl: './create-post.component.html',
|
|
})
|
|
export class CreatePostComponent {
|
|
private postsService = inject(PostsService);
|
|
private location = inject(Location);
|
|
post = signal<Post>({
|
|
id: 0,
|
|
title: '',
|
|
tldr: '',
|
|
content: '',
|
|
});
|
|
|
|
constructor() {
|
|
setTimeout(() => {
|
|
this.post.set({ ...this.post(), title: 'adf' });
|
|
}, 1000);
|
|
}
|
|
|
|
publish() {
|
|
this.postsService.createPost(this.post());
|
|
this.location.back();
|
|
}
|
|
}
|