0

第一:对不起我的英语我不太擅长这种语言。

我有一个小问题。对于我的考试,我必须创建一个电影院管理应用程序。我刚开始,我已经遇到了问题。

我希望主页显示我必须在名为 home.ts 的文件中注册的电影院名称列表。

但是在测试页面并重新启动程序之后,再次制定遗嘱:我的标题显示但不显示电影院名称列表。

我不知道为什么这不起作用。

我把我当前的代码放在这里,这样你就可以更好地理解我的上下文以及可能是什么问题。

主页.html:

 <ion-header>
  <ion-navbar>
    <ion-title>
     Bienvenu sur myCiné
    </ion-title>
  </ion-navbar>
</ion-header>
  <ion-navbar color="primary">
    <button menuToggle ion-button icon-only>
      <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>myCiné</ion-title>
  </ion-navbar>

  <ion-toolbar color="secondary">
    <ion-title>Mes cinémas favoris</ion-title>
  </ion-toolbar>

<ion-content padding>
  <ion-grid *ngIf="cinemas">
    <ion-row>
      <ion-col col-1 *ngFor="let cinema of cinemas">
        {{cinema.name}}
      </ion-col>
    </ion-row>
  </ion-grid>
</ion-content>

home.ts :

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  cinemas: [
    {
      id: 1,
      name: "Méga CGR La mézière",
      adress: "Zone de Millet",
      cp: "35320",
      ville: "La Mézière",
      nbSalles:"12",
      accesH:"oui",
      proj3D: "oui",
      stand: "oui",
      lesPlus:"Salle ICE"
    },
    {
      id: 2,
      name: "Pathé Atlantis",
      adress: "8 allée de la pérouse",
      cp: "44800",
      ville: "Saint Herblain",
      nbSalles:"12",
      accesH:"oui",
      proj3D: "oui",
      stand: "oui",
      lesPlus:"Salle IMAX"
    },
    {
      id: 3,
      name: "Gaumont Nantes",
      adress: "12 place du commerce",
      cp: "44000",
      ville: "Nantes",
      nbSalles:"14",
      accesH:"oui",
      proj3D: "oui",
      stand: "oui",
      lesPlus:"Salle IMAX"
    },
    {
      id: 4,
      name: "Méga CGR La Rochelle",
      adress: "Avenue Heri Becqurel",
      cp: "17000",
      ville: "La Rochelle",
      nbSalles:"13",
      accesH:"oui",
      proj3D: "oui",
      stand: "oui",
      lesPlus:"Salle ICE"
    }
  ]

  constructor(public navCtrl: NavController) {

  }
}

感谢您的回答,祝您有愉快的一天。

4

1 回答 1

0

您需要在代码中修复“电影院”的分配:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  // here use assignment rather than comma:
  cinemas = [
    {
      id: 1,
      name: "Méga CGR La mézière",
      adress: "Zone de Millet",
      cp: "35320",
      ville: "La Mézière",
      nbSalles:"12",
      accesH:"oui",
      proj3D: "oui",
      stand: "oui",
      lesPlus:"Salle ICE"
    },
    {
      id: 2,
      name: "Pathé Atlantis",
      adress: "8 allée de la pérouse",
      cp: "44800",
      ville: "Saint Herblain",
      nbSalles:"12",
      accesH:"oui",
      proj3D: "oui",
      stand: "oui",
      lesPlus:"Salle IMAX"
    },
    {
      id: 3,
      name: "Gaumont Nantes",
      adress: "12 place du commerce",
      cp: "44000",
      ville: "Nantes",
      nbSalles:"14",
      accesH:"oui",
      proj3D: "oui",
      stand: "oui",
      lesPlus:"Salle IMAX"
    },
    {
      id: 4,
      name: "Méga CGR La Rochelle",
      adress: "Avenue Heri Becqurel",
      cp: "17000",
      ville: "La Rochelle",
      nbSalles:"13",
      accesH:"oui",
      proj3D: "oui",
      stand: "oui",
      lesPlus:"Salle ICE"
    }
  ]

  constructor(public navCtrl: NavController) {

  }
}

为了使它更好,您可以在构造函数之前使用类型声明变量,然后在构造函数中进行赋值。这是一种更标准的方法:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

interface Cinema {
    id: number,
    name: string,
    adress: string,
    cp: string,
    ville: string,
    nbSalles: string,
    accesH: string,
    proj3D: string,
    stand: string,
    lesPlus: string
}

@Component({
    selector: 'page-home',
    templateUrl: 'home.html'
})
export class HomePage {
    // here we can declare var and its type:
    cinemas: Array<Cinema>;

    constructor(public navCtrl: NavController) {
        // here we can do assignments:
        this.cinemas = [
            {
                id: 1,
                name: "Méga CGR La mézière",
                adress: "Zone de Millet",
                cp: "35320",
                ville: "La Mézière",
                nbSalles: "12",
                accesH: "oui",
                proj3D: "oui",
                stand: "oui",
                lesPlus: "Salle ICE"
            },
            {
                id: 2,
                name: "Pathé Atlantis",
                adress: "8 allée de la pérouse",
                cp: "44800",
                ville: "Saint Herblain",
                nbSalles: "12",
                accesH: "oui",
                proj3D: "oui",
                stand: "oui",
                lesPlus: "Salle IMAX"
            },
            {
                id: 3,
                name: "Gaumont Nantes",
                adress: "12 place du commerce",
                cp: "44000",
                ville: "Nantes",
                nbSalles: "14",
                accesH: "oui",
                proj3D: "oui",
                stand: "oui",
                lesPlus: "Salle IMAX"
            },
            {
                id: 4,
                name: "Méga CGR La Rochelle",
                adress: "Avenue Heri Becqurel",
                cp: "17000",
                ville: "La Rochelle",
                nbSalles: "13",
                accesH: "oui",
                proj3D: "oui",
                stand: "oui",
                lesPlus: "Salle ICE"
            }
        ]
    }
}
于 2018-07-14T15:58:15.213 回答