小编Sam*_*amy的帖子

如何在 Angular 4.3 中使用两个 HttpClient 实例(一个有 2 个拦截器,另一个有 1 个拦截器)?

在我们的Angular 4.3项目中,我们分别有公共站点组件和安全站点(登录)组件。我们使用@angular/common/http. 我们想为public-site组件和secured-site组件实现不同的http拦截器。例如,

  1. 公共站点组件 - 仅在拦截器下方应用
    LoggingInterceptor
  2. 安全站点组件 - 在两个拦截器下方应用
    LoggingInterceptor
    AuthTokenInterceptor(在请求标头中传递身份验证令牌)

我们尝试使用不同的拦截器HTTP_INTERCEPTORS在每个组件级别添加提供者详细信息@Component。但是请求不会进入任何拦截器。

仅当我们HTTP_INTERCEPTORS@NgModule. 这里的问题是,公共站点 http 请求也会进入AuthTokenInterceptor不需要的。

那么我们应该如何解决这个问题呢?谢谢。

http-headers angular-http-interceptors angular

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

bootstrap-select 下拉选项有时未加载

我正在使用 bootstrap-select 1.12.4 版本和 Angular 4.3.5。

我正在尝试使用 http 调用和异步管道加载下拉选项。

我面临的问题是,刷新页面时,大多数情况下都不会加载选择下拉选项。但有时选项会加载。我不确定我在这里犯了什么错误。有人能帮我一下吗?提前致谢。

组件.ts

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';    
import { Observable } from 'rxjs';

@Component({
  selector: 'app-bob-report',
  templateUrl: './bob-report.component.html',
  styleUrls: ['./bob-report.component.css']
})
export class BobReportComponent implements OnInit {

  observableOptions: Observable<any>;

  constructor(private http: HttpClient) { }

  ngOnInit() {
    this.observableOptions = this.http.get('assets/data/users.json');
  }

}
Run Code Online (Sandbox Code Playgroud)

组件.html

<form>
  <div class="form-group">
    <label for="sel1">Select list (select one):</label>
    <select class="selectpicker" data-live-search="true">
      <option *ngFor="let option of observableOptions | async" value={{option.id}}> {{option.value}} </option> …
Run Code Online (Sandbox Code Playgroud)

bootstrap-select angular

0
推荐指数
1
解决办法
1万
查看次数