我正在使用智能管理模板以表格格式顯示數據。在angular2中動態綁定數據表不起作用
我試圖綁定數據與硬編碼的數據它的工作原理,但是當我從ngOnInit上的component.ts打到service.ts並設置爲this.data。雖然它設置但不顯示到ui/component.html。
請參閱下面的代碼。如果需要更多幫助,請讓我知道。
1. component.html裏面我寫了: -
<sa-datatable ng-data="data" [options]="{
colReorder: true,
data: data,
columns: [ {data: 'apiKey'}, {data: 'name'}]}"
paginationLength="true" tableClass="table table-striped table-bordered table-hover" width="100%">
<thead>
<tr>
<th data-hide="phone">APIKey</th>
<th data-class="expand">
<i class="fa fa-fw fa-user text-muted hidden-md hidden-sm hidden-xs"></i>
Name
</th>
</tr>
</thead>
</sa-datatable>
2.內部component.ts
import { Component, OnInit } from '@angular/core';
import {JsonApiService} from "../shared/api/json-api.service";
import {Observable} from 'rxjs/Rx';
import {Router, CanActivate } from '@angular/router';
@Component({
selector: 'administration-apps',
templateUrl: './administration.apps.component.html',
styleUrls: ['./administration.component.css'],
providers: [JsonApiService]
})
export class AdministrationAppsComponent implements OnInit {
//data = [{ "_id": "5807f24c762c48a0b548318f", "accountID": "580170af762c48a0b548318e", "name": "EZ FORMSTest 4", "active": true, "apiKey": "b2878c30-bea0-11e4-983f-d9ec76fdf276" }, { "_id": "580170af762c48a0b008318e", "accountID": "580170af762c48a0b54831ff", "name": "EZ FORMSTest 5", "__v": 0, "active": true, "apiKey": "b2878c30-bea0-11e4-983f-d9ec76fdf276" }];
private data: any;
private errorMessage: string;
constructor(private jsonApiService: JsonApiService, private router: Router) {
}
createNewApp() {
this.router.navigate(['/administration/apps/new'])
}
ngOnInit() {
this.data = this.jsonApiService.getApps()
.subscribe((apps: any) => { this.data = apps; console.log('looking for data now'); console.log(this.data);},
error => this.errorMessage = error);
}
}
3內部JSON-api.service。 ts
getApps(): any {
return this.httpGet('/app');
}
httpGet(path) {
let headers = new Headers({ 'X-TOKEN': '2f348e80-a26c-11e6-aea2- b1b9938df75f' });
let options = new RequestOptions({ headers: headers });
return this.http.get(this.baseURL + path, options)
.map((res: Response) => res.json())
.map(forms => {
return forms;
})
.catch(this.handleError);
}