-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniil Myasnikov
committed
Dec 27, 2016
1 parent
f9149a0
commit 9f397a7
Showing
2 changed files
with
41 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export class Person { | ||
id: number; | ||
name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
]; | ||
} | ||
} |