小编Mig*_*ura的帖子

Angular 7 的 Simple ModalService 无法打开:找不到组件工厂

我正在创建一个 Angular 的 7 ModalService,它只是打开一个 Modal(StackBlitz Example)。

Modal 内容应该是打开时传递给 Modal 的 Component。

模态

export class Modal {

  protected modal: any = null;

  close() {
    this.modal.close();
  }

}
Run Code Online (Sandbox Code Playgroud)

模态服务

import { ApplicationRef, ComponentFactoryResolver, EmbeddedViewRef, Injectable, Injector } from '@angular/core';

@Injectable({
  providedIn: 'root'
})

export class ModalService {

  private componentRef: any;
  private modalContainer: any;

  constructor(
    private componentFactoryResolver: ComponentFactoryResolver,
    private appRef: ApplicationRef,
    private injector: Injector) { }

  private createFormModal(component: any): Element {

    this.componentRef = this.componentFactoryResolver.resolveComponentFactory(component.component).create(this.injector);

    this.componentRef.instance.modal = this;

    this.appRef.attachView(this.componentRef.hostView);

    return (this.componentRef.hostView …
Run Code Online (Sandbox Code Playgroud)

angular angular7

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

将数组转换为Type of Message消息

我从Angular的API响应中收到以下内容

(response) => {

  let messages: Message[] = response.messages;

  for (let message: Message in messages) {

    let description = message.description;

  }
Run Code Online (Sandbox Code Playgroud)

但在let description = message.description;我得到错误:

Property 'description' does not exist on type 'string'.
Run Code Online (Sandbox Code Playgroud)

这是因为我使用的是类而不是接口吗?

消息应该在我的代码中被认为是消息类型吗?

响应类似于:

[
  { description: "Some description", type: "1029BA" },
  { description: "Other description", type: "20sdBC" }
]
Run Code Online (Sandbox Code Playgroud)

而消息是一个类.

export class Message {

  description: string;
  type: string;

  constructor(description: string, type?: string) {
    this.description = description;
    this.type = type;
  }    

}
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

使用 UserManagerGenerateUserTokenAsync 创建带有额外数据的自定义令牌

我正在使用 ASP.NET Core 2.2,我需要在我的应用程序中生成自定义令牌。

Asp.Net Core Identity UserManager 可以生成经典令牌,例如 EmailVerification,...

但它还有一种生成具有不同用途的令牌的方法(MSFT Docs):

public virtual System.Threading.Tasks.Task<string> GenerateUserTokenAsync (TUser user, string tokenProvider, string purpose);
Run Code Online (Sandbox Code Playgroud)

我需要生成包含以下信息的令牌:

  1. 目的 = 添加用户到项目
  2. 用户 = 给定用户
  3. ProjectId = 应添加用户的项目 ID。
  4. RoleId = 用户在项目中的角色 ID

在GenerateUserTokenAsync上我可以添加用户和目的......

但我不知道如何添加(3)和(4),例如ProjectId和RoleId。

我怎样才能稍后检索它以便我可以实际执行该操作。

我该怎么做?

usermanager asp.net-core asp.net-core-identity asp.net-core-2.2

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

作业在上一个作业完成之前开始

我有一个包含两个作业(job: Publishdeployment: Deploy)的 Azure Pipelines 阶段。

有时作业在完成deployment: Deploy之前就开始运行job: Publish

我收到错误,然后我需要等待job: Publish完成并重新运行deployment: Deploy

当我重新运行时deployment: Deploy一切顺利......

问题
为什么deployment: Deploy先开始后job: Publish结束?

这是该阶段的 YML 代码:

- stage: Production
  dependsOn: Staging
  jobs:
  - job: Publish
    pool:
      vmImage: 'Ubuntu 16.04'
    steps:
    - task: UseDotNet@2
      displayName: Setup
      inputs:
        packageType: sdk
        version: 3.0.x
    - task: DotNetCoreCLI@2
      displayName: Publish
      inputs:
        command: publish
        publishWebProjects: false
        projects: 'src/**/*.csproj'
        arguments: '--configuration production --output $(Build.ArtifactStagingDirectory)' …
Run Code Online (Sandbox Code Playgroud)

azure-pipelines

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

类型“OperatorFunction&lt;未知,[未知,布尔值,任意]&gt;”上不存在属性“管道”

使用 Angular 9,我需要根据返回两个可观察值的两种方法检查条件:

    return zip(this.authService.isSignedIn(), this.authService.getRole()).pipe(
      map(([isSignedIn, role]: [boolean, string]) => isSignedIn && role && role.toLowerCase() === 'admin')
    );
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

 Property 'pipe' does not exist on type 'OperatorFunction<unknown, [unknown, boolean, any]>
Run Code Online (Sandbox Code Playgroud)

我缺少什么?

observable rxjs angular angular9

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

在 RXJS Tap 操作符内部时,Console.Log 不会执行

我有以下观察结果:

this.authenticationService.isSignedIn() -> Observable<Boolean>

this.user$ -> Observable<UserModel>
Run Code Online (Sandbox Code Playgroud)

我需要根据两者检查条件,所以我尝试了:

zip(this.authenticationService.isSignedIn(), this.user$).pipe(
  map(([isSignedIn, user]: [boolean, UserModel]) => isSignedIn && user.claims))
); 
Run Code Online (Sandbox Code Playgroud)

因为我得到了意想不到的结果,所以我尝试使用以下方法检查内容:

zip(this.authenticationService.isSignedIn(), this.user$).pipe(
  tap(([isSignedIn, user]: [boolean, UserModel]) => {
    console.log(isSignedIn);
    console.log(user);
  })
);
Run Code Online (Sandbox Code Playgroud)

但两人console.log并没有被处决。我缺少什么?

rxjs typescript angular angular10

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

使用 OpenIdDict 时不允许使用“offline_access”范围

将 Asp.Net Core 5.0 与 Identity 和 OpenIdDict 结合使用我有以下内容:

  services.AddOpenIddict()
  
    .AddCore(x => {
      x.UseEntityFrameworkCore().UseDbContext<Context>().ReplaceDefaultEntities<Application, Authorization, Scope, Token, Int32>();
    })

    .AddServer(x => {

      x.SetAuthorizationEndpointUris("/connect/authorize")
       .SetLogoutEndpointUris("/connect/logout")
       .SetTokenEndpointUris("/connect/token")
       .SetUserinfoEndpointUris("/connect/userinfo");

      x.RegisterScopes(OpenIddictConstants.Scopes.Profile, OpenIddictConstants.Scopes.Email, OpenIddictConstants.Scopes.OfflineAccess);

      x.AllowAuthorizationCodeFlow();

      x.AddDevelopmentEncryptionCertificate().AddDevelopmentSigningCertificate();

      x.UseAspNetCore()
       .EnableAuthorizationEndpointPassthrough()
       .EnableLogoutEndpointPassthrough()
       .EnableTokenEndpointPassthrough()
       .EnableUserinfoEndpointPassthrough()
       .EnableStatusCodePagesIntegration();

    })

    .AddValidation(x => {
      x.UseLocalServer();
      x.UseAspNetCore();
    });
Run Code Online (Sandbox Code Playgroud)

我有以下客户:

  OpenIddictApplicationDescriptor spa = new OpenIddictApplicationDescriptor {
    ClientId = "spa",
    ClientSecret = "secret",
    ConsentType = OpenIddictConstants.ConsentTypes.Implicit,
    PostLogoutRedirectUris = {
      new Uri("https://localhost:5002/oidc-signout")
    },
    RedirectUris = {
      new Uri("https://localhost:5002/oidc-signin"),
      new Uri("https://localhost:5002/oidc-silent-refresh")
    },
    Permissions = {
      OpenIddictConstants.Permissions.Endpoints.Authorization,
      OpenIddictConstants.Permissions.Endpoints.Logout,
      OpenIddictConstants.Permissions.Endpoints.Token, …
Run Code Online (Sandbox Code Playgroud)

asp.net-core openiddict asp.net-core-5.0

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

如何将 List&lt;List&lt;Int32&gt;&gt; 的初始化简化为 IEnumerable&lt;IEnumerable&lt;Int32&gt;&gt;?

我正在做以下集合初始化:

Int32[,] v1 = new Int32[2, 2] { { 1, 2 }, { 3, 4 } };

IEnumerable<IEnumerable<Int32>> v2 = new List<List<Int32>> { { 2, 3 }, { 3, 4 } };
Run Code Online (Sandbox Code Playgroud)

在第二行我得到错误:

No overload for method 'Add' takes 2 arguments
Run Code Online (Sandbox Code Playgroud)

有没有办法使用最新的 C# 版本为主集合中的每个项目创建一个IEnumerable<IEnumerable<Int32>>而不添加new List<Int32>

IEnumerable<IEnumerable<Int32>> v2 = new List<List<Int32>> { 
  new List<Int32> { 2, 3 }, 
  new List<Int32> { 3, 4 } 
};
Run Code Online (Sandbox Code Playgroud)

c# ienumerable list nested-lists new-operator

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

如何在 .NET 6 / C# 10 中将 List&lt;String?&gt; 转换为 List&lt;String&gt;?

使用 .NET 6 我有以下内容:

List<String> values = new List<String?> { null, "", "value" }
  .Where(x => !String.IsNullOrEmpty(x))
  .Select(y => y)
  .ToList();
Run Code Online (Sandbox Code Playgroud)

但我收到警告:

类型“string?[]”的值中引用类型的可为空性与目标类型“string[]”不匹配。

我以为使用

.Where(x => !String.IsNullOrEmpty(x))
Run Code Online (Sandbox Code Playgroud)

可以解决问题,但没有。如何解决这个问题?

c# .net-6.0 c#-10.0

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

删除子对象

我正在尝试更新资源,如下所示:

  public void Update(Resource resource) {

   Resource _resource = _resourceRepository.First(r => r.Id == resource.Id);

   _resource.Content = resource.Content;
   _resource.Description = resource.Description;
   _resource.Locked = resource.Locked;
   _resource.Name = resource.Name;

   _resource.Restrictions.ToList().ForEach(r => _resource.Restrictions.Remove(r));

   foreach (Restriction restriction in resource.Restrictions)
    _resource.Restrictions.Add(new Restriction { Property = _propertyRepository.First(p => p.Id == restriction.Property.Id), Value = restriction.Value });

  } // Update
Run Code Online (Sandbox Code Playgroud)

我有一些类似的工作,创建一个只有一个区别的资源:我没有删除限制.

我收到以下错误:

来自'Restrictions_ResourceId_FK'AssociationSet的关系处于'已删除'状态.给定多重约束,相应的"限制"也必须处于"已删除"状态.

我错过了什么?

entity-framework child-objects

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