【发布时间】:2017-03-18 04:04:00
【问题描述】:
我正在使用 Smart Admin Template 以表格格式显示数据。
我尝试将数据与硬编码数据绑定,但当我从 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。内部组件.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);
}
【问题讨论】:
标签: angular