Skip to content

Commit

Permalink
our first model
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Myasnikov committed Dec 27, 2016
1 parent f9149a0 commit 9f397a7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
4 changes: 4 additions & 0 deletions app/model/person.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class Person {
id: number;
name: string;
}
68 changes: 37 additions & 31 deletions app/tasks/list.component.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,60 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';

import { Person } from '../model/person';

@Component({
selector: 'list',
templateUrl: './app/templates/list.html',
})
export class ListComponent {
persons: Object[] = [
{
"id" : 1,
"name": 'Ms. Jackson'
},
{
"id" : 2,
"name": 'Mr. Philips'
},
{
"id" : 3,
"name": 'Cusine Susy'
},
{
"id" : 4,
"name": 'Antonio'
},
{
"id" : 5,
"name": 'Carl'
},
{
"id" : 6,
"name": 'Lisa'
}
];
export class ListComponent implements OnInit {
persons: Person[];

lastId: number = 6;

add(name: string = '') {
add(name: string = ''): boolean {
this.lastId++;
let person: Object = {
let person: Person = {
"id": this.lastId,
"name": name
};
this.persons.push(person);
return false;
}

delete(person: Object = null) {
delete(person: Person = null): void {
let index = this.persons.indexOf(person);

if ( index > -1 ) {
this.persons.splice(index, 1);
}
}

ngOnInit(): void {
this.persons = [
{
"id" : 1,
"name": 'Ms. Jackson'
},
{
"id" : 2,
"name": 'Mr. Philips'
},
{
"id" : 3,
"name": 'Cusine Susy'
},
{
"id" : 4,
"name": 'Antonio'
},
{
"id" : 5,
"name": 'Carl'
},
{
"id" : 6,
"name": 'Lisa'
}
];
}
}

0 comments on commit 9f397a7

Please sign in to comment.