在Angular 7中解析过程中的HTTP失败



我正在实现kendo下拉菜单,并在用户试图通过输入字符搜索时试图调用API。我可以看到正在对API进行调用,并且API正在返回过滤值,但是数据没有受到限制。

我可以看到发生了错误,并且执行了错误块。错误指出

http http失败http://localhost:54455/fund/hfrfundsearch?term = as

有人可以告诉我问题是什么。是因为API返回对象

这是我的代码

 <label for="inputFax" class="col-md-2  col-form-label header">Third Party Database Feed</label>
 <div class="col-md-3">
       <div *ngIf="!EditMode">{{FundDetails.HFRFundName}}</div>
         <kendo-dropdownlist style="width:350px" [(ngModel)]="HFRFunds" [data]="HFRFunds"  [filterable]="true" [valuePrimitive]="true"   textField="text" valueField="id"  (filterChange)="handleFilter($event)"></kendo-dropdownlist>
 </div>

组件

 handleFilter(value) {
        if (value.length >= 2) {
            this.fundService.getHFRFund(value)
            .subscribe(data => {
                this.HFRFunds = data;
            },
                err => {
                    this.Error = 'An error has occurred. Please contact BSG';
                },
                () => {
                });
        }
    }

服务

 constructor(
            private http: HttpClient,
            private config: AppConfig)
    { }
 getHFRFund(value : string) {
                let pars = new HttpParams();
                pars = pars.append('term', value.toString());
                const url = this.config.api.hfrFundSearch;
                return this.http.get(url, { params: pars, withCredentials: true });
        }

API。

[HttpGet]
        [AuthorizationLevel(AuthAccessLevel.Read)]
        public object HFRFundSearch(string term)
        {
            try
            {
                var hfrFunds = new List<object>();
                if (!string.IsNullOrEmpty(term))
                {
                    term = term.ToLower();
                    hfrFunds.AddRange(GetViewService<V_HFR_FUND>()
                        .Where(x => x.HFR_FUND_NAME.ToLower().StartsWith(term))
                        .Take(10)
                        .OrderBy(x => x.HFR_FUND_NAME)
                        .Select(x => new { id = x.HFR_FUND_ID, text = x.HFR_FUND_NAME })
                        .ToList());
                }
                return hfrFunds;
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return ex;
            }
        }
// API
[HttpGet]
        [AuthorizationLevel(AuthAccessLevel.Read)]
        public object HFRFundSearch(string term)
        {
            try
            {
                var hfrFunds = new List<object>();
                if (!string.IsNullOrEmpty(term))
                {
                    term = term.ToLower();
                    hfrFunds.AddRange(GetViewService<V_HFR_FUND>()
                        .Where(x => x.HFR_FUND_NAME.ToLower().StartsWith(term))
                        .Take(10)
                        .OrderBy(x => x.HFR_FUND_NAME)
                        .Select(x => new { value = x.HFR_FUND_ID, text = x.HFR_FUND_NAME })
                        .ToList());
                }
                return hfrFunds;
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return ex;
            }
        }

    // component
     // component
    import { map } from 'rxjs/operators';
    handleFilter(value) {            
       if (value.length >= 2) {                     
          this.fundService.getHFRFund(value).subscribe(
                data => {
                 this.HRFunds = data;
           });           
        }
    }

最新更新