代码之家  ›  专栏  ›  技术社区  ›  Cpt Kitkat Anu

如何以角度显示snakbar中对象的数据

  •  0
  • Cpt Kitkat Anu  · 技术社区  · 6 年前

    解析Json的代码:

        this.messageService.messageReceived$.subscribe(data => {
    
            this.snakbar.statusBar("Platform job Completed - " + data, "Info");
            let webService: WebService = JSON.parse(data);
            console.log(webService.message);
            console.log(webService.executionId);
            console.log(webService.code);
            this.spinner.hide();
            this.selectedIndex = 1;
    }
    

    interface WebService {
    jobId: string,
    executionId: string,
    code: number,
    message: string,
    data: string
    }
    

    使用控制台.log我可以在中查看数据控制台。但是我想用snakbar显示消息。 现在我得到了 'Platform job Completed - [Object][Object]' 我想要这样的东西在snakbar 'Platform job Completed - Success/Failure Info"'

    我如何实现这一点?

    1 回复  |  直到 6 年前
        1
  •  1
  •   UI_Dev    6 年前

    首先将订阅的值赋给某个变量。

    this.data = data;
    

    this.snakbar.statusBar("Platform job Completed - " + this.data.message, "Info");
    

    const project = JSON.parse(this.dataService.getObject("project"));
        if (project != null) {
            this.globalAppSateService.onMessage(project);
            this.project = project;
        }
        this.messageService.messageReceived$.subscribe(data => {
            this.data = data; // assigning data to reuse
            this.snakbar.statusBar("Platform job Completed - " + this.data.message, "Info");
            let webService: WebService = JSON.parse(data);
            console.log(webService.message);
            console.log(webService.executionId);
            console.log(webService.code);
            this.spinner.hide();
            this.selectedIndex = 1;
    }
    
    推荐文章