[英]Angular 2: Cannot read property 'then' of undefined for push notification
我試圖在按鈕點擊時顯示推送通知。
我陷入角度承諾錯誤,說:
無法讀取未定義的屬性'then'
完整錯誤堆棧跟蹤:
未捕獲的錯誤:./AppComponent類中的錯誤AppComponent - 內聯模板:17:2導致:無法讀取未定義的屬性'then'
TypeError:無法在DebugAppView.eventHandler的DebugAppView.View_AppComponent0.handleEvent_16(/AppModule/AppComponent/component.ngfactory.js:129)的PushNotificationComponent.show(notification.component.js:42)中讀取未定義的屬性'then'(視圖。 js:664)位於ZoneDelegate的Object.NgZone.forkInnerZoneWithAngularBehavior.inner.inner.fork.onInvokeTask(ng_zone.js:264)的ZoneDelegate.invokeTask(zone.js:367)的HTMLButtonElement.COMPONENT_REGEX(dom_renderer.js:489)。在ZoneBuntonElement.cancelFn.invoke(zone.js:420)的Zone.runTask(zone.js:166)中的invokeTask(zone.js:366)
我正在使用github鏈接:
https://github.com/alexcastillo/ng2-notifications/blob/master/src/app/app.component.html
我的app.module.ts如下:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { PushNotificationComponent } from 'ng2-notifications/src/app/components/notification.component';
@NgModule({
declarations: [
AppComponent,
PushNotificationComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts
import { Component } from '@angular/core';
import {
Directive,
EventEmitter,
OnInit,
OnChanges,
OnDestroy,
Input,
Output
} from '@angular/core';
import '../style/app.scss';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
@Directive({
selector: 'push-notification'
})
export class AppComponent {
title: string = 'ng2-notifications';
description: string = 'Angular 2 Component for Native Push Notifications';
constructor() {
}
}
app.component.html
<header>
<h1 class="title">{{ title }}</h1>
</header>
<main>
<h2>{{ description }}</h2>
<img src="img/demo.gif">
<push-notification #notification title="ng2-notifications" body="Native Push Notifications in Angular 2" icon="<some_ulr>" closeDelay="2000" (load)="notification.show()"> //Problem Here!!
</push-notification>
<button (click)="notification.show()">Show Notification</button>
</main>
如果我刪除行:( (load)="notification.show()
它似乎很好,但它沒有任何目的沒有通知后按鈕點擊!
錯誤在這里:
從app.component.ts中刪除此代碼塊
@Directive({
selector: 'push-notification'
})
注意 :
https://github.com/alexcastillo/ng2-notifications使用角度測試版進行編碼,因此請查找更新版本或不同的插件。
鑒於Doc還涉及角度的beta版本
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.