javascript - 异常 : TypeError: undefined is not an object (evaluating 'pipe.constructor' ) in Ionic 2?

标签 javascript pipe angular remote-debugging ionic2

我的 Ionic 2 应用程序在 Chrome 浏览器上运行良好,它提供了预期的输出。但是当它在模拟器或浏览器上运行时出现以下错误。

这是我正在使用的代码:

<label class="time">{{appointment.DateSent | date:"HH"}}:{{ appointment.DateSent| date:"mm"}}</label>
<label class="month">{{appointment.DateSent| date:"MMM"}}</label>
<label class="day">{{appointment.DateSent| date:"dd"}}</label>
<label class="year">{{appointment.DateSent| date:"yyyy"}}</label>

类实现:

    import {Page, NavController, NavParams} from 'ionic/ionic';
    import { Component, Pipe, PipeTransform, Inject, OnInit} from 'angular2/core';
    import 'rxjs/add/operator/map';
    import { Http, Headers, URLSearchParams } from 'angular2/http';
    import {SERVER_URL, appName, alertAppName} from '../services/config';
    import {AppointmentsDetailPage} from '../appointments-detail/appointments-detail';
    import {MessagesService} from '../services/messages-service';

    var today = new Date();

    @Page({
      templateUrl: 'build/pages/appointments/appointments.html',
      providers: [MessagesService]
    })
    export class AppointmentsPage implements PipeTransform {
      constructor(http: Http, nav: NavController, messagesService:MessagesService, navParams:NavParams) {
            this.http = http;
            this.messagesService = messagesService;
            this.nav = nav;

            this.selectedItem = navParams.get('item');
      }

ngOnInit() {
        this.messagesService.getAppointmentList()
        .subscribe(data => {

          var appointments = new Array();
              for(var i in data){
                var key = data[i];

                appointments.push({
                  MessageID: key.MessageID,
                  CategoryID: key.CategoryID,
                  DateSent: new Date(key.DateSent),
                  Title: key.Title,
                  MessageContent: key.MessageContent,
                  Sender: key.Sender,
                  Recipient: key.Recipient,
                  DateReceived: key.DateReceived,
                  DateRead: key.DateRead,
                  Note_Direction: key.Note_Direction,
                  Viewed: key.Viewed,
                  AppointmentDateTime: key.AppointmentDateTime,
                  MessageAttachments: key.MessageAttachments
                });
              }


      this.appointments = appointments;

所有日期管道在 Chrome 浏览器中都工作正常,没有错误,但在模拟器或设备上出现以下异常(取自 Safari 模拟器调试)

enter image description here

已编辑:

索引.html

<!DOCTYPE html>
<html dir="ltr" lang="en">

<head>
  <title>Ionic</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

  <!--<meta http-equiv="Content-Security-Policy" content="img-src 'self' data:; default-src 'self' http://XX.XX.XX.XX:8084/mypp/">-->
  <!--<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src  'self' 'unsafe-inline' *">-->
  <meta name="format-detection" content="telephone=no">
  <meta name="msapplication-tap-highlight" content="no">

  <link rel="stylesheet" href="build/css/font-awesome.min.css">
  <link ios-href="build/css/app.ios.css" rel="stylesheet">
  <link md-href="build/css/app.md.css" rel="stylesheet">



</head>

<body>
  <ion-app></ion-app>

  <script src="node_modules/es6-shim/es6-shim.min.js"></script>
  <script src="node_modules/systemjs/dist/system-polyfills.js"></script>
  <script src="lib/ngCordova/dist/ng-cordova.js"></script>
  <script src="cordova.js"></script>
  <script src="build/js/app.bundle.js"></script>
</body>

</html>

最佳答案

您应该加载 polyfill(Chrome 可以在没有它们的情况下运行 Angular):

<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>

关于javascript - 异常 : TypeError: undefined is not an object (evaluating 'pipe.constructor' ) in Ionic 2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35742679/

相关文章:

javascript - ES6 导入定义的执行顺序是什么?

javascript - Protractor 无法单击与 $timeout 关联的链接

c# - 检查 NamedPipeServerStream 是否在客户端启动的方法

c - Linux C 中循环中的 fork 和管道进程

css - 根据 div 中的宽度响应元素

javascript - 无法将 sails-auth 库集成到 sails 项目中

javascript - 以编程方式设置 grunt 任务的选项?

regex - 如何使用标准 linux utils 删除前导空格

node.js - Angular 4 : Unknown error after POST request to REST api on localhost

angular - 错误 TypeError : this. Remember.forEach 不是 AuthFormComponent.ngAfterContentInit 中的函数