正在调用警报服务消息,但未显示警报。我正在使用 Angular 2 框架。
我添加了警报代码如下。
Alert.ts 文件。
import { Component, OnInit } from '@angular/core';
import { AlertService } from './alert.service';
@Component({
selector: 'alert',
templateUrl: 'alert.html'
})
export class AlertComponent {
message: any;
constructor(private alertService: AlertService) { }
ngOnInit() {
console.log("Calling init function");
this.alertService.getMessage().subscribe(message => { this.message = message; });
}
}
Run Code Online (Sandbox Code Playgroud)
警报服务.ts
import { Injectable } from '@angular/core';
import { Router, NavigationStart } from '@angular/router';
import { Observable } from 'rxjs';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class …Run Code Online (Sandbox Code Playgroud)