【发布时间】:2018-04-30 19:02:53
【问题描述】:
我正在尝试显示数据库中的数据。然后我想验证每个数据是否存在于另一个表中,所以我需要向我的后台发送请求以检查这些数据。然后我需要显示它是否有效。
问题是*ngIf 不起作用,它表明我的提供程序功能不起作用。
这是 HTML 页面:
<ion-row *ngFor="let obj of listObj">
<ion-col col-8>
<ion-icon name="md-checkmark-circle-outline"></ion-icon>
<p>Objectif : {{obj.id_obj}} </p>
<p id="nameobj"> {{obj.des_obj | titlecase}}</p>
</ion-col>
<ion-col col-4 *ngIf="testobj(obj.id_obj_ser).length">
<p>lol</p>
<!--
<p id="valide">Vue</p>
<p id="non-valide">Non Vue</p>-->
</ion-col>
</ion-row>
这是我的控制器:
export class ObjectifEnsPage {
listObj = <[any]>[];
testiObj = <[any]>[];
id_stage: number;
cin: number;
test: boolean;
constructor(public navCtrl: NavController, public navParams: NavParams, private etudiant: EtudiantProvider) {
this.id_stage = this.navParams.get('stage');
this.cin = this.navParams.get('cin');
console.log("el stage w el cin ahawma" + this.id_stage, this.cin);
}
ionViewDidLoad() {
console.log('ionViewDidLoad ObjectifEnsPage');
this.getobjectif()
}
getobjectif() {
this.etudiant.getobjectif(this.id_stage).subscribe((data: any) => {
this.listObj = data;
console.log(data);
}, error => {
console.log(error);
});
}
testobj(id: number): any {
this.etudiant.getobjectifvalidation(id, this.cin).subscribe((data: any) => {
this.testiObj = data;
}, error => {
console.log(error);
});
}
}
【问题讨论】:
-
请用您遇到的确切错误更新您的问题。
-
但是你没有返回一个布尔值,如果你会从方法中返回一个真值。毕竟这是一个 If 条件。
-
@DanielWSrimpel 在 testobject 函数上进入无限循环
-
我认为您的流程完全颠倒了。您可能正在经历这个“无限循环”,因为每次 Angular 启动更改检测周期时,您的
testobj函数都会在该*ngIf中运行。您正在加载数据并将其设置在您的对象上(通过this.testiObj属性),这将触发另一个更改检测周期......从而调用您的testobj函数。您能否提供控制器代码,以便我们尝试帮助您朝另一个方向发展? -
就是这样,我想做的是验证收到的数据是否不为空,然后 ngif 工作。 @DanielWSrimpel
标签: angular http ionic-framework angular-ng-if