小编Mic*_*l D的帖子

Angular Azure Active Directory B2C 身份验证 - CORS 问题

我正在 Angular 中实现 Azure Active Directory B2C 身份验证。我正在使用 msal 拦截器连接 Azure AD B2C。身份验证请求失败并显示错误

CORS 策略阻止了在 ' https://login.microsoftonline.com/ ...' 从源 ' http://localhost/ ...'访问 XMLHttpRequest :没有 'Access-Control-Allow-Origin' 标头存在于请求的资源上。

浏览器控制台截图

我根据这篇文章配置了一切:https : //medium.com/@sambowenhughes/configuring-your-angular-6-application-to-use-microsoft-b2c-authentication-99a9ff1403b3

azure-ad-b2c azure-ad-msal azure-authentication angular

11
推荐指数
1
解决办法
1819
查看次数

带有键值管道的 ngFor:类型“未知”不可分配给类型“NgIterable<any>”

我正在尝试迭代这个对象

{
  "2021-11-22": [
    {
      "id": 1,
      "standard_id": 2,
      "user_id": 4,
      "subject_id": 1,
      "exam_date": "2021-11-22",
      "start_time": "09:45:00",
      "end_time": "02:52:00",
      "description": "kjhkjhkjhkjhkj\n\n\njgfhgfhgfghfghfhg",
      "deleted_at": null,
      "created_at": "2021-11-22T03:47:34.000000Z",
      "updated_at": "2021-11-22T03:47:34.000000Z",
      "subject": {
        "id": 1,
        "standard_id": 2,
        "name": "engilsh",
        "deleted_at": null,
        "created_at": "2021-11-21T07:11:15.000000Z",
        "updated_at": "2021-11-21T07:11:15.000000Z"
      }
    },
    {
      "id": 2,
      "standard_id": 2,
      "user_id": 4,
      "subject_id": 2,
      "exam_date": "2021-11-22",
      "start_time": "09:45:00",
      "end_time": "10:45:00",
      "description": "kjhkjhkjhkjhkj\n\n\njgfhgfhgfghfghfhg",
      "deleted_at": null,
      "created_at": "2021-11-22T03:49:41.000000Z",
      "updated_at": "2021-11-22T03:49:41.000000Z",
      "subject": {
        "id": 2,
        "standard_id": 2,
        "name": "Physics",
        "deleted_at": null,
        "created_at": "2021-11-21T07:17:25.000000Z",
        "updated_at": "2021-11-21T07:17:25.000000Z" …
Run Code Online (Sandbox Code Playgroud)

ngfor angular

9
推荐指数
1
解决办法
7599
查看次数

在 Angular 中开玩笑测试后如何自动调用discardPeriodicTasks?

我做了一个一次性订阅,debounceTime在我的组件上有一个管道onInit

this.subscriptions.add(
  this.updateJobs$
    .pipe(
      filter(jobs => !!jobs.length),
      debounceTime(MyComponent.ListStabilizationTimeInMS),
      first(),
    )
    .subscribe((jobs: Update[]) => {
      // some code
    })
);
Run Code Online (Sandbox Code Playgroud)

因此,我需要discardPeriodicTasks();在每次fakeAsync测试后将其作为最后一行包含在内,我觉得这很乏味。否则我会收到Error: 1 periodic timer(s) still in the queue.所有测试的错误。

我试图创建一个afterEach

afterEach(()=> {
  discardPeriodicTasks();
});

afterEach(fakeAsync(()=> {
  discardPeriodicTasks();
}));
Run Code Online (Sandbox Code Playgroud)

但它不起作用,通过测试的唯一方法是手动附加discardPeriodicTasks();到所有测试用例。如果可以自动化就太好了。

jestjs angular

8
推荐指数
0
解决办法
1347
查看次数

避免在 Angular 2+ 中嵌套订阅?

我有两个端点:

  • 1 个端点来获取当前用户的登录信息。
  • 1 个端点来获得此用户的授权。

其实我用:

this.user
  .subscribe((e) => {
     this.grants.get(e)
        .subscribe((x) => {
            console.log(x)
         })
  })
Run Code Online (Sandbox Code Playgroud)

但这是 Angular 2+/RxJS 的反模式。

我想知道如何按照 Angular/RxJS 最佳实践执行此操作。

谢谢

rxjs angular

6
推荐指数
1
解决办法
687
查看次数

Angular 9.0.7 Ivy:BrowserAnimationsModule 没有被 ngcc 正确处理,或者与 Angular Ivy 不兼容

我创建了一个新的 Angular 项目并收到以下错误:

这可能意味着声明 BrowserAnimationsModule 的库 (@angular/platform-b​​rowser/animations) 没有被 ngcc 正确处理,或者与 Angular Ivy 不兼容

我的 Angular 版本是:9.0.7

按照此处的建议我尝试删除node_modules并重新安装它,但没有帮助。

angular

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

无法访问 Angular 模板中的枚举

我的目的是使用枚举来读取数组的属性。这段代码给我错误:

<ng-container *ngFor="let elem of list">
  <div class="ui-g-12 ui-sm-12 ui-md-12  ui-lg-12 ui-xl-12">
    <div class="ui-g-12 ui-sm-12 ui-md-12 ui-lg-3 ui-xl-3">
      <input type="text" pInputText value="{{elem[StudentEnum.name] }}" name="student_name" />
    </div>
</ng-container>
Run Code Online (Sandbox Code Playgroud)

StudentEnum是一个枚举类,但是如果我放入模板中它就不起作用。在模板中使用枚举读取数组属性和值的正确方法是什么?

{{ elem[StudentEnum.name] }}
Run Code Online (Sandbox Code Playgroud)

enums typescript angular2-template angular

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

Angular 8:如何使用 Observable 的时间间隔立即发送 http 请求

我具有将请求从前端连续发送到后端的功能。所以我添加了如下代码。

我想以第一个请求立即发出然后在两分钟后发出的方式实施。

但使用下面的代码并根据间隔的定义,它将在两分钟后发送第一个请求。

this.getData = Observable.interval(2 * 60 * 1000)
      .pipe(flatMap(() => this.service.getData(b, b, b, b, b, b))).subscribe();
Run Code Online (Sandbox Code Playgroud)

我不想通过先添加请求然后添加上述代码来重复代码,也不想通过任何其他方式来完成它。

observable rxjs angular angular8

4
推荐指数
1
解决办法
1008
查看次数

角度ActivatedRoute中的this.route.params和this.route.snapshot.params有什么区别

constructor(private recipeService : RecipeService , private route : ActivatedRoute) { }

  ngOnInit() {
    const id = this.route.params['id'];
const id = this.route.snapshot.params['id'];
  }
Run Code Online (Sandbox Code Playgroud)

角度中的route.snapshot.params和route.params有什么区别我们什么时候应该使用route.snapshot.params,什么时候应该使用route.params

angular

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

在 Angular 中解析来自 Http 请求的 json 响应

我需要解析包含两个键的 json 响应。响应看起来像

{
status: 0;
message: 'some error 404'
}
Run Code Online (Sandbox Code Playgroud)

在纯 Nodejs 或 React 中,你可以简单地执行以下操作if (response.status===1)console.log('success')

然而,我在角度上做这件事一直很困难。有人可以指导我并告诉我如何解析 JSON 响应吗?我附上了代码的模型。

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Component } from '@angular/core';

@Component({
    selector: 'app-create-employee',
    templateUrl: './create-employee.component.html',
    styleUrls: ['./create-employee.component.css']
})

export class CreateEmployeeComponent {
    
    constructor(private http: HttpClient) { };
    
    onFormSubmit() {
        let options = {
            headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
        };
        
        let body = new URLSearchParams();
        body.set('data', 'stackoverflow');
            

        this.http.post('http://localhost:8080/createEmployee', body.toString(), options)
        .subscribe(response => {
            console.log(response.status);
            console.log(response.message);
        });
    } …
Run Code Online (Sandbox Code Playgroud)

json angular

2
推荐指数
1
解决办法
9668
查看次数

从 Angular 中的 PrimeNG PickList 中删除按钮

在下图中,我希望只有单项选择按钮并删除选择所有按钮(由黑色气泡标记)。

选项列表截图

我正在使用PrimeNG Picklist来生成列表。

有人可以帮助我吗?

picklist primeng angular

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

如何检查 .pipe(map) Rxjs 操作符中的空响应?

getDetailsById(eId: number): Observable<Details> {
  return this.api.post('detailsapi', cacheOptions, { Id: eId })
    .pipe(
      map((eDetails: any) => ({
        id: eDetails.eId,
        subDetails: this.mapSubDetails(eDetails.eSubDetails || [])
      })),
      catchError((err) => {
        const template: Template = {   
          id: 0,
          subEquipment: []
        };
        return Observable.throw(err)
      })
    );
}
Run Code Online (Sandbox Code Playgroud)

我想检查上面的代码是否eDetails为空。如果为空,那么我想停止 Observable.forkJoin.

javascript observable rxjs typescript angular

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