【问题标题】:Ionic value from variable not shown in html来自变量的离子值未在 html 中显示
【发布时间】:2020-01-03 01:42:53
【问题描述】:

我创建了一个新的 Ionic 应用程序并尝试在 HTML 中显示一个变量的值,但我无法让它工作。

这是我的页面,我没有更改任何内容。我刚刚创建了应用程序。

import { IonicModule } from '@ionic/angular';
import { RouterModule } from '@angular/router';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Tab1Page } from './tab1.page';
import { SongsProviderService } from '../Services/songs-provider.service';

@NgModule({
    imports: [
        IonicModule,
        CommonModule,
        FormsModule,
        RouterModule.forChild([{ path: '', component: Tab1Page }])
    ],
    declarations: [Tab1Page]
})

export class Tab1PageModule {

    songs: any;
    bla: any;

    constructor(public songsService: SongsProviderService) {
        this.bla = "sss";
        console.log(this.bla);
    }

}

HTML:

<ion-header>
    <ion-toolbar>
        <ion-title>
            Tab One
        </ion-title>
    </ion-toolbar>
</ion-header>

<ion-content>
    <ion-content>
        <p>Test {{bla}}</p>
    </ion-content>
</ion-content>

【问题讨论】:

  • 您遇到的错误究竟是什么。页面是否显示但{{bla}} 只输出一个空字符串?

标签: angular typescript ionic-framework


【解决方案1】:

我想知道原因是否是因为有两个 &lt;ion-content&gt; 元素。这篇文章指出应该只有一个:https://ionicframework.com/docs/api/content

【讨论】:

    猜你喜欢
    • 2021-05-09
    • 2018-06-16
    • 1970-01-01
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    • 2019-06-18
    相关资源
    最近更新 更多