angular4-testing/project-manager/src/app/blog/blog.component.ts

45 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-03-02 23:26:26 +01:00
import {Component} from '@angular/core';
import {ActivatedRoute, ActivatedRouteSnapshot, Router, RouterStateSnapshot} from '@angular/router';
import {Title} from '@angular/platform-browser';
import {initialEntries} from './initialEntries';
2017-03-03 09:05:29 +01:00
import {BlogEntry} from './blog-entry/blog-entry';
2017-03-02 23:26:26 +01:00
@Component({
selector: 'blog',
templateUrl: 'blog.component.html',
styleUrls: ['blog.component.css']
})
export class BlogComponent {
entries: BlogEntry[] = [];
id = 0;
constructor(r: ActivatedRoute, private router: Router, private titleService: Title) {
this.entries = [];
this.entries = initialEntries;
this.id = this.entries[this.entries.length-1].id;
}
createBlogEntry(title:string, image:string, text:string) {
this.id++;
console.log(this.id, title, image, text);
let entry = new BlogEntry();
entry.id = this.id;
entry.title = title;
entry.image = image;
entry.text = text;
this.entries.push(entry);
}
deleteBlogEntry(id:number) {
let entryIndex = this.entries.findIndex(entry => entry.id === id);
if (entryIndex > -1) {
this.entries.splice(entryIndex, 1);
}
}
}