src/app/app-poll/app-poll-list.component.ts
selector | app-poll-list |
styleUrls | ./app-poll-list.component.less |
templateUrl | ./app-poll-list.component.html |
Properties |
Methods |
constructor(pollService: AppPollService)
|
||||||
Parameters :
|
getLatestPoll | ||||||
getLatestPoll(ps: AppPoll[])
|
||||||
Parameters :
Returns :
AppPoll
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
update | ||||||
update(event: Event)
|
||||||
Parameters :
Returns :
void
|
data |
data:
|
Type : any
|
errorMessage |
errorMessage:
|
Type : string
|
Default value : ''
|
poll |
poll:
|
Type : AppPoll
|
polls |
polls:
|
Type : AppPoll[]
|
pResult |
pResult:
|
Type : AppPollResult
|
import { Component, OnInit } from '@angular/core';
import { AppPoll } from './app-poll';
import { AppPollService } from './app-poll.service';
import { ElementRef } from '@angular/core/src/linker/element_ref';
import { AppPollResultsService } from './app-poll-results.service';
import { AppPollResult } from 'src/app/app-poll/app-poll-result';
@Component({
selector: 'app-poll-list',
templateUrl: './app-poll-list.component.html',
styleUrls: ['./app-poll-list.component.less']
})
export class AppPollListComponent implements OnInit {
data: any;
polls: AppPoll[];
poll : AppPoll;
errorMessage = '';
pResult: AppPollResult;
constructor(private pollService: AppPollService
//, private pollResultService: AppPollResultsService
) { }
ngOnInit() {
this.pollService.getPolls().subscribe(
polls => {
this.polls = polls;
this.poll = this.getLatestPoll(this.polls);
},
error => this.errorMessage = <any>error)
}
getLatestPoll(ps: AppPoll[]): AppPoll{
const sortedPolls: AppPoll[] = this.polls.sort((poll1: AppPoll, poll2: AppPoll )=>
poll2.publishedDate - poll1.publishedDate);
return sortedPolls[0];
}
// getPollResult(pId: number): void{
// this.pollResultService.getPollResult(pId).subscribe(
// pollResult => {
// this.pResult = pollResult;
// },
// error => this.errorMessage = <any>error)
// }
update(event: Event) {
//this.data = //create new data
}
}
<app-poll [poll] = poll></app-poll>
<section>
<div class="row">
<div *ngFor="let poll of polls; let i = index;" class="col-sm-12 col-md-6 card">
<div class="row card-body">
<div class="col-sm-3">
<img class="width-inherit" src="../assets/doughnutChart.png" alt="Comparision chart" />
</div>
<div class="col-sm-6">
<div>
<h6>{{poll?.publishedDate | date}}</h6>
</div>
<div>
<h5> {{poll.title}}</h5>
</div>
</div>
</div>
</div>
</div>
</section>
./app-poll-list.component.less
img.width-inherit{
width: inherit;
}