简体   繁体   English

如何在角度6和vmware-clarity中的UI中显示错误消息

[英]How can I show error message in the UI in angular 6 and vmware-clarity

Hi I am new to angular and Clarity, How can I show error message,http errors and other errors, in the UI using angular 6 and Clarity. 嗨,我是angular和Clarity的新手,如何在UI中使用angular 6和Clarity显示错误消息,http错误和其他错误。 below is a little code snippet from one of my component where you can see (err: any) => console.log(err), I want to show error message in the UI using Clarity Standard alert and App level alert, instead of consoling it. 下面是我的一个组件中的一个小代码片段,您可以在其中看到(err:any)=> console.log(err),我想使用Clarity Standard警报和App级警报在UI中显示错误消息,而不是安慰它。 Please let me know how can I achieve this.Thanks in advance. 请让我知道如何实现此目标。

ngOnInit() {
 this.dataStorageService.getLocations()
  .subscribe(res => {
   for (let i = 0; i < res.Locations.length; i++) {
    const quoteReplaceData = res.Locations[i].replace(/'/g, '"');
     this.locationList.push(JSON.parse(quoteReplaceData));
   }
  }, (err: any) => console.log(err),
 () => console.log('All done getting incidents'));
//In your typescript file, define a variable
error: any;

ngOnInit() {
 this.dataStorageService.getLocations()
  .subscribe(res => {
   for (let i = 0; i < res.Locations.length; i++) {
    const quoteReplaceData = res.Locations[i].replace(/'/g, '"');
     this.locationList.push(JSON.parse(quoteReplaceData));
   }
  }, (err: any) => this.error = err,
 () => console.log('All done getting incidents'));

and in your view: 并且在您看来:

<div class="alert alert-danger" *ngIf="error">
    <div class="alert-items">
        <div class="alert-item static">
            <div class="alert-icon-wrapper">
                <clr-icon class="alert-icon" shape="exclamation-circle"></clr-icon>
            </div>
            <span class="alert-text">
                {{error}}
            </span>
        </div>
    </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM