我无法弄清楚如何正确打印从我的服务,CompanyProvider返回的数据。
import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {CompanyProvider} from "../../../providers/company/company";
@IonicPage()
@Component({
selector: 'page-settings-company',
templateUrl: 'settings-company.html',
})
export class SettingsCompanyPage {
companyInfo:any;
jobs: any;
maquinaria:any;
otrosDocumentos:any;
constructor(public navCtrl: NavController, public navParams: NavParams, public _cp: CompanyProvider) {
console.log("You're in settingsCompany");
this.createForm();
}
createForm() {
console.log("CRETE FORM");
let idCompany = this.navParams.get('id');
console.log("ID DE Compañia desde Settings-company : " + idCompany);
//get CompanyInfo
this._cp.getCompanyInfo(idCompany).then(
companyInfo=>this.companyInfo=companyInfo
)
//get Jobs
this._cp.getJobs(idCompany).then(data => {
this.jobs = data;}
)
//get maquinaria
this._cp.getMaquinaria(idCompany).then(data => {
this.maquinaria = data;}
)
//get otros_dcoumentos
this._cp.getOtrosDocumentos(idCompany).then(data => {
this.otrosDocumentos = data;}
)
}
}
我不知道在将数据传递给用于在视图中打印的局部变量之前是否需要处理数据。
我在视图中使用以下内容:
<ion-content padding>
<ion-list>
<h4>{{companyInfo|json}}</h4>
<h4>{{jobs | json}}</h4>
</ion-list>
</ion-content>
结果是:
我已尝试过以下操作,但这并没有返回任何内容,而控制台告诉我它未定义。在第二个Json中,我不知道如何使用ngfor循环占用。
<h4>{{companyInfo.name}}</h4>
答案 0 :(得分:0)
在companyInfo
中呈现.html
,我在name
ion-item
<ion-content padding>
<ion-list>
<ion-item *ngFor="let eachItem of companyInfo"
<h4>{{eachItem.name}}</h4>
</ion-item>
</ion-list>
</ion-content>
答案 1 :(得分:-1)
请尝试此类型示例: -
<div *ngIf="companyInfo && companyInfo.length">
<div *ngFor="let company of companyInfo">
<h4>{{company.name}}</h4>
</div>
</div>