<table class="table table-striped">
<tr>
<th>
Season
</th>
<th>
Vacation
</th>
</tr>
<tr *ngFor = "let item of allvalues | paginate: { itemsPerPage: 10, currentPage:p }">
<td>
{{item.Name}}
</td>
<td>
{{item.Vacation}}
</td>
</tr>
</table>
<pagination-controls (pageChange)="p=$event"></pagination-controls>
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { TestHttpServiceService } from '../test-http-service.service';
class SeasonClass
{
Name: string;
Vacation: boolean;
}
class AllSeasons {
Seasons: SeasonClass[];
}
@Component({
selector: 'app-about',
templateUrl: './about.component.html',
styleUrls: ['./about.component.css'],
providers: [ TestHttpServiceService ]
})
export class AboutComponent implements OnInit {
allvalues=[];
AllSeasonsObj: AllSeasons;
@Output() onSuggest: EventEmitter<string> = new EventEmitter();
// Service
constructor(private _service: TestHttpServiceService) { }
ngOnInit() {
var str: string;
this.onSuggest.subscribe((sub: string) =>
{
this.AllSeasonsObj = JSON.parse(sub) as AllSeasons;
this.allvalues = this.AllSeasonsObj.Seasons;
});
this._service.GetTestStr(this.onSuggest);
}
}
import { Injectable, Output, EventEmitter } from '@angular/core';
import { Http } from '@angular/http';
@Injectable()
export class TestHttpServiceService {
constructor(private _http: Http) { }
public GetTestStr(ev: EventEmitter<string>) {
var str: string;
str = "xxx";
setTimeout(function() {
}, (1000));
this._http.get("assets/testxx.json").subscribe((sub) =>
{
// str = JSON.stringify(sub.text());
str = sub.text();
console.log(str);
ev.emit(str);
}
);
}
}
Copyright©1996-2021,Tapuz Media Ltd. Forum software by XenForo® © 2010-2020 XenForo Ltd.