【问题标题】:Unhandled Promise rejection: Template parse errors:未处理的承诺拒绝:模板解析错误:
【发布时间】:2017-05-21 19:07:42
【问题描述】:

我正在使用 Ionic 2 试图让 Firebase 基于this tutorial 工作,但使用 Ionic rc4。任何帮助表示赞赏。

Your system information:

 ordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.4
Ionic CLI Version: 2.1.18
Ionic App Lib Version: 2.1.9
Ionic App Scripts Version: 0.0.47
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.9.2
Xcode version: Not installed

没有编译错误,但出现以下运行时错误:

Unhandled Promise rejection: Template parse errors:
'h7' is not a known element:
1. If 'h7' is an Angular component, then verify that it is part of this module.
2. If 'h7' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("
      </h2>
      <p class="chat-text">{{item.chat_text}}</p>
      [ERROR ->]<h7 class="chat-time">{{item.timestamp | date:'dd/MM/yyyy'}}</h7>
    </ion-item>
  </ion-list>
"): HomePage@23:6 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:
'h7' is not a known element:
1. If 'h7' is an Angular component, then verify that it is part of this module.
2. If 'h7' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("
      </h2>
      <p class="chat-text">{{item.chat_text}}</p>
      [ERROR ->]<h7 class="chat-time">{{item.timestamp | date:'dd/MM/yyyy'}}</h7>
    </ion-item>
  </ion-list>
"): HomePage@23:6
Stack trace:
TemplateParser</TemplateParser.prototype.parse@http://localhost:8100/build/main.js:20796:19
RuntimeCompiler</RuntimeCompiler.prototype._compileTemplate@http://localhost:8100/build/main.js:45698:30
RuntimeCompiler</RuntimeCompiler.prototype._compileComponents/<@http://localhost:8100/build/main.js:45618:56

它似乎引用了HomePage,但我不确定它是否有任何错误。 home.ts

import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import {LoginPage} from '../login/login';
import {
  FirebaseAuth,
  AngularFire,
  FirebaseListObservable
} from 'angularfire2';


@Component({
  templateUrl: 'home.html'
})
export class HomePage {
  firelist: FirebaseListObservable<any>;
  chat: any;
  constructor(public nav: NavController, public af: AngularFire, public auth: FirebaseAuth) {
    this.firelist = this.af.database.list('/chat', { //mengambil data
      query: {
        orderByChild: 'negativtimestamp', //order dari data yang terbaru
      }
    });
  }

  chatSend(va, vi) { //mengirim pesan chat
    this.af.database.list('/chat').push({ // menambahkan data chat ke firebase
      uid: window.localStorage.getItem('uid'),
      img: window.localStorage.getItem('photoURL'),
      username: window.localStorage.getItem('displayName'),
      chat_text: va.chatText,
      timestamp: Date.now(),
      negativtimestamp: -Date.now() //buat nanti ambil data yang terbaru
    })
    this.chat = '';
  }

  logout() { // melakukan logout
    window.localStorage.removeItem('email'); // remove email dari localStorage
    window.localStorage.removeItem('uid'); // remove uid dari localStorage
    window.localStorage.removeItem('displayName'); // remove displayName dari localStorage
    this.auth.logout();
    this.nav.setRoot(LoginPage);// kembali ke halaman LoginPage
  }

}

【问题讨论】:

  • 谢谢,这看起来像错误。这是我从教程下载的代码。我看到 html 有一个 标签。我修改一下看看。

标签: firebase ionic2


【解决方案1】:

转换为答案:您的模板中有一个标签无法通过解析器,该标签是

<h7> 

改成

<h3>

例如,它应该可以工作(或者将它放在一个 div 中,并使用 CSS 类根据需要设置它的样式)。

【讨论】:

    【解决方案2】:

    HTML 5 中不存在 h7 标签。这是您的错误。这不是 ionic 或 firebase 错误。只需将 h7 更改为 h6 或其他一些标签,此错误就会消失

    【讨论】:

      猜你喜欢
      • 2017-11-24
      • 1970-01-01
      • 1970-01-01
      • 2017-01-07
      • 1970-01-01
      • 1970-01-01
      • 2018-11-08
      • 2019-10-27
      • 2017-02-06
      相关资源
      最近更新 更多