import { Component } from
'@angular/core'
;
interface Book {
name: String,
author: String,
year: Number
}
@Component({
selector:
'app-root'
,
templateUrl:
'./app.component.html'
,
styles: [
`.frozen-row{
font-weight: bold;
}`
]
})
export class AppComponent {
frozenBooks: Book[] = [];
unfrozenBooks: Book[] = [];
ngOnInit() {
this
.unfrozenBooks = [
{
name:
"Clean Code"
,
author:
"Robert Cecil Martin"
,
year: 2008
},
{
name:
"Refactoring"
,
author:
"Martin Fowler"
,
year: 1999
},
{
name:
"Code Complete"
,
author:
"Steve McConnell"
,
year: 1993
},
{
name:
"Programming Pearls"
,
author:
"John Bentley"
,
year: 1986
},
{
name:
"The Clean Coder"
,
author:
"Robert Cecil Martin"
,
year: 2011
},
{
name:
"Coders at Work"
,
author:
"Peter Seibel"
,
year: 2009
},
{
name:
"Effective Java"
,
author:
"Joshua Bloch"
,
year: 2001
},
{
name:
"Head First Java"
,
author:
"Bert Bates"
,
year: 2003
}
];
this
.frozenBooks = [
{
name:
"Introduction to Algorithms"
,
author:
"Thomas H Corman"
,
year: 1989
}
];
}
toggleFreeze(book: Book, isFreezed: boolean, i: Number)
{
if
(isFreezed) {
this
.frozenBooks =
this
.frozenBooks.filter((c, index) => index !== i);
this
.unfrozenBooks.push(book);
}
else
{
this
.unfrozenBooks =
this
.unfrozenBooks.filter((c, index) => index !== i);
this
.frozenBooks.push(book);
}
}
}