gpt4 book ai didi

ionic2 - ionic 2 : *ngFor not displaying data

转载 作者:行者123 更新时间:2023-12-02 04:34:40 24 4
gpt4 key购买 nike

ngFor 在 HTML 中不起作用。我在我的应用程序中只使用了一个模块。我尝试了很多解决方案但没有解决这个问题。控制台中没有任何错误。这是我的代码

电影.ts

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { Storage } from '@ionic/storage';



@Component({
selector: 'page-movie',
templateUrl: 'movie.html',
})
export class Movie {
http: any;
movies_cats: any;

constructor(public navCtrl: NavController, public navParams: NavParams, private storage: Storage, http: Http) {
this.http = http;
return this.http.get('link.php?a=' + this.navParams.data.code + '&m=' + this.navParams.data.mac + '&s=' + this.navParams.data.serial + '&k=' + this.navParams.data.key + '&p=vodMovieList')
.map(res => res.json())
.subscribe(response => {
this.movies_cats = response.vod_categories.vod_category;
console.log(this.movies_cats);
});
}
}

电影.html

<ion-header>
<ion-navbar>
<ion-title>movie</ion-title>
</ion-navbar>
</ion-header>

<ion-content>
<ion-grid class="grid_div">
<ion-row class="grid_row">
<ion-col col-3 class="grid_col">
<ion-scroll scrollY class="scroll_bar">
<div class="scroll-item" *ngFor="let cat of movies_cats">
<p>name</p>
</div>
</ion-scroll>
</ion-col>
<ion-col col-9>SUB CATEGORIES</ion-col>
</ion-row>
</ion-grid>
</ion-content>

应用程序模块.ts

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import {IonicStorageModule} from '@ionic/storage';

import { HttpModule} from '@angular/http';


import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { Categories } from '../pages/categories/categories';
import { Live } from '../pages/live/live';
import { Movie } from '../pages/movie/movie';


@NgModule({
declarations: [
MyApp,
HomePage,
Categories,Movie,Live
],
imports: [
BrowserModule,HttpModule,
IonicModule.forRoot(MyApp),IonicStorageModule.forRoot(),
IonicStorageModule.forRoot({
name: '__mydb',
driverOrder: ['indexeddb', 'sqlite', 'websql']
})
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
Categories,Movie,Live
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},Storage
]
})
export class AppModule {}

JSON response

最后我希望 div 重复 3 次,例如响应中的对象数而不打印 cat。问题是 HTML 中什么也没有出现

最佳答案

import { FormsModule} from '@angular/forms';
import { CommonModule } from '@angular/common';



imports: [
BrowserModule,
AppRoutingModule,
FormsModule,
CommonModule
],

关于ionic2 - ionic 2 : *ngFor not displaying data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44688103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com