小编kan*_*lal的帖子

警报服务在 Angular 2 中不起作用

正在调用警报服务消息,但未显示警报。我正在使用 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)

alert modal-dialog angular

5
推荐指数
1
解决办法
2303
查看次数

标签 统计

alert ×1

angular ×1

modal-dialog ×1