我正在创建一个 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的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) 我正在使用 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)
我需要生成包含以下信息的令牌:
在GenerateUserTokenAsync上我可以添加用户和目的......
但我不知道如何添加(3)和(4),例如ProjectId和RoleId。
我怎样才能稍后检索它以便我可以实际执行该操作。
我该怎么做?
usermanager asp.net-core asp.net-core-identity asp.net-core-2.2
我有一个包含两个作业(job: Publish
和deployment: 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) 使用 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)
我缺少什么?
我有以下观察结果:
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
并没有被处决。我缺少什么?
将 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) 我正在做以下集合初始化:
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) 使用 .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)
可以解决问题,但没有。如何解决这个问题?
我正在尝试更新资源,如下所示:
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的关系处于'已删除'状态.给定多重约束,相应的"限制"也必须处于"已删除"状态.
我错过了什么?
angular ×4
asp.net-core ×2
c# ×2
rxjs ×2
typescript ×2
.net-6.0 ×1
angular10 ×1
angular7 ×1
angular9 ×1
c#-10.0 ×1
ienumerable ×1
list ×1
nested-lists ×1
new-operator ×1
observable ×1
openiddict ×1
usermanager ×1