小编kel*_*mat的帖子

Angular 的“CanActivate”接口已弃用。如何更换?

我的 Angular 应用程序包含一个简单的应用程序,AuthGuard如下所示,并且从未出现过问题。最近,我将 Angular 版本从 15.1.4 升级到 15.2.0,从那时起,我的 IDE 表明 和CanActivate均已CanActivateChild弃用。

Angular 的官方文档说CanActivate

已弃用:使用纯 JavaScript 函数代替。

我需要如何调整下面的代码以消除已弃用的警告?

export class AuthGuard implements CanActivate, CanActivateChild {

    constructor(private authService: AuthenticationService) {}

    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree  {
        return this.authService.checkLogin()
            .pipe(
                map(() => true),
                catchError(() => {
                    this.router.navigate(['route-to-fallback-page']);
                    return of(false);
                }
            )
        );
    }

    canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | …
Run Code Online (Sandbox Code Playgroud)

canactivate angular auth-guard canactivatechild candeactivate

74
推荐指数
3
解决办法
7万
查看次数

Angular Material 15:如何自定义按钮和输入字段的样式?

我想覆盖 Angular Material 15 按钮和输入字段中的字体宽度。

Material 文档在这里说我应该在样式表中执行此操作:

@use '@angular/material' as mat;

$my-custom-level: mat.define-typography-level(
  $font-family: Roboto,
  $font-weight: 400,
  $font-size: 1rem,
  $line-height: 1,
  $letter-spacing: normal,
);
Run Code Online (Sandbox Code Playgroud)

我不认为这段代码实际上“应用”了我的字体更改,我想它需要应用于当前主题或其他东西,我尝试了各种方法,但不知道如何应用它。任何提示将不胜感激。

我尝试创建自定义主题,但无法弄清楚在哪里应用 $my-custom-level:

$config: mat.define-typography-config();

$theme: mat.define-light-theme((                                                    
    typography: $config,
));

@include mat.input-typography($theme);
Run Code Online (Sandbox Code Playgroud)

angular-material angular angular-material-15

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

如何使用 Angular 限制并发 http 请求的数量?

假设我要上传 100 张图像,因此我的 Angular 前端必须进行 100 个 API 调用。然而,由于后端限制,我希望在任何给定时间点最多同时有 5 个 API 请求。每当队列中的一个 http 请求完成时,就应该添加并执行另一个请求。

我怎样才能实现这个目标?

observable rxjs angular angular14

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

如何通过 POST 请求从 Angular 向 .Net API 提交数据

我试图调用一个简单的请求,但 API 中的值(属性)为空。你有什么建议吗?

C#

[Route("getpagefields")]
[AcceptVerbs(WebRequestMethods.Http.Post)]
public IHttpActionResult GetPageFields([FromBody]string property)
{
   USERS user = TokenUtils.Authonticate(Request);
                
   return Ok(new { fields = WebServiceBL.GetPageFields(property) });
}
Run Code Online (Sandbox Code Playgroud)

.ts

GetPageFields(){
  debugger;
  let urlPart = this.router.url.split('/')[3];
  let params = new HttpParams();
  params = params.set('data', urlPart);
  let test = this._httpClient.post(environment.apiBaseUrl+'users/getpagefields',params).subscribe(() => {   
 });
}
Run Code Online (Sandbox Code Playgroud)

示例截图

c# angular

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