我正在 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
我正在尝试迭代这个对象
{
"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) 我做了一个一次性订阅,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();到所有测试用例。如果可以自动化就太好了。
我有两个端点:
其实我用:
this.user
.subscribe((e) => {
this.grants.get(e)
.subscribe((x) => {
console.log(x)
})
})
Run Code Online (Sandbox Code Playgroud)
但这是 Angular 2+/RxJS 的反模式。
我想知道如何按照 Angular/RxJS 最佳实践执行此操作。
谢谢
我创建了一个新的 Angular 项目并收到以下错误:
这可能意味着声明 BrowserAnimationsModule 的库 (@angular/platform-browser/animations) 没有被 ngcc 正确处理,或者与 Angular Ivy 不兼容
我的 Angular 版本是:9.0.7
我的目的是使用枚举来读取数组的属性。这段代码给我错误:
<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) 我具有将请求从前端连续发送到后端的功能。所以我添加了如下代码。
我想以第一个请求立即发出然后在两分钟后发出的方式实施。
但使用下面的代码并根据间隔的定义,它将在两分钟后发送第一个请求。
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)
我不想通过先添加请求然后添加上述代码来重复代码,也不想通过任何其他方式来完成它。
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
我需要解析包含两个键的 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) 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.
angular ×11
rxjs ×3
observable ×2
typescript ×2
angular8 ×1
azure-ad-b2c ×1
enums ×1
javascript ×1
jestjs ×1
json ×1
ngfor ×1
picklist ×1
primeng ×1