Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class PostService {
- posts = [
- {
- title: "Post 1",
- content: "bla bla bla",
- loveIts: 0,
- created_at: new Date,
- },
- {
- title: "Post 2",
- content: "bla bla bla",
- loveIts: 0,
- created_at: new Date,
- },
- {
- title: "Post 3",
- content: "bla bla bla",
- loveIts: 0,
- created_at: new Date,
- },
- ];
- getPosts() {
- return this.posts;
- }
- setLoveItsToDefault() {
- for (let post of this.posts) {
- post.loveIts = 0;
- }
- }
- initializeLovesPost(i: number) {
- this.posts[i].loveIts = 0;
- }
- }
- export class AppComponent {
- @Input() posts : Post[];
- constructor(private postService: PostService) {
- }
- ngOnInit() {
- this.posts = this.postService.getPosts();
- }
- onInitializeLoves() {
- if (confirm('Are you sure to initialize all loves of all posts to 0 ?')) {
- this.postService.setLoveItsToDefault();
- } else {
- return null;
- }
- }
- }
- <button class="btn btn-primary" (click)="onInitializeLoves()">Initialize loves to 0</button>
Add Comment
Please, Sign In to add comment