我想使用 Angular 的接口实现自定义跨字段验证器ValidatorFn。
这是我的代码:(我按照https://angular.io/guide/form-validation#cross-field-validation上提供的步骤进行操作)
import { ValidatorFn, ValidationErrors, FormGroup } from "@angular/forms";
/**
* This validator implements the ValidatorFn Interface from Angular.
*
* @param formGroup- the FormGroup that needs Validation
*
* @returns null if the form is valid, else some {@link ValidatorErrors}
*/
export const CompleteBloodpressureValidator: ValidatorFn = (formGroup: FormGroup) => {
const bloodpressureSys = formGroup.get("bloodPressureSysFormControl");
const bloodpressureDia = formGroup.get("bloodPressureDiaFormControl");
if (bloodpressureSys != null && bloodpressureDia == null || bloodpressureSys == null && bloodpressureDia …Run Code Online (Sandbox Code Playgroud) 我想将多个分组的条形图合并为一张图,如下图所示。 将条形图分组到单个图中
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
labels = ['G1', 'G2', 'G3']
yesterday_test1_mean = [20, 12, 23]
yesterday_test2_mean = [21, 14, 25]
today_test1_mean = [18, 10, 12]
today_test2_mean = [13, 13, 9]
Run Code Online (Sandbox Code Playgroud)
首先,我创建了每个分组条形图plt.subplots()
x = np.arange(len(labels))
width = 0.3
fig1, ax = plt.subplots()
rects1 = ax.bar(x-width/2, yesterday_test1_mean, width)
rects2 = ax.bar(x+width/2, yesterday_test2_mean, width)
fig2, ax = plt.subplots()
rects3 = ax.bar(x-width/2, today_test1_mean, width)
rects4 = ax.bar(x+width/2, today_test2_mean, width)
Run Code Online (Sandbox Code Playgroud)
然后,我尝试add_subplot将fig1和fig2作为新图形中的新轴。 …
在我的 Blazor 项目中,我使用两个_Host.cshtml文件。第一个是默认_Host.cshtml文件。另一种用于授予对特定.razor页面的匿名登录访问权限。假设匿名剃刀页面是x.razor。
X.剃刀
@page '\PublicRazor\x'
...
Run Code Online (Sandbox Code Playgroud)
第一个场景
我将在不登录的情况下访问
x.razor页面。在这种情况下,中的所有功能都x.razor不起作用(例如按钮单击、表单验证)。当我检查开发者控制台时,我看到了这个
第二个场景
x.razor登录 blazor 应用程序后我将转到页面。在这种情况下,所有功能都x.razor可以正常工作。并且开发者控制台没有任何错误。
为什么会发生这种情况?如何使x.razor所有功能进入工作状态?
默认_Host.cshtml
@page "/"
@using Microsoft.AspNetCore.Authorization
@namespace has.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@attribute [Authorize]
@{
Layout = null;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>has</title>
<base href="~/" />
<link href="_content/Blazor.ContextMenu/blazorContextMenu.min.css" rel="stylesheet" />
<script src="~/js/site.js"></script>
</head>
<body>
<app>
<component type="typeof(App)" render-mode="Server" />
</app>
<script …Run Code Online (Sandbox Code Playgroud) I added Angular Material to my project using Angular-CLI. I selected the Purple/Green pre-built theme. According to the preview of the theme, the background color should be dark. But my background color still white. Why doesn't my background color change to dark? Any solution?
我有一个 .net cor 3.1 Blazor 服务器项目。我在这个项目中使用默认的身份系统。我想在不登录的情况下访问特定的剃须刀页面。我怎么做?任何想法?
我尝试添加@attribute [AllowAnonymous]到剃刀页面。但这对我不起作用
_Host.cshtml
page "/"
@using Microsoft.AspNetCore.Authorization
@namespace has.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@attribute [Authorize]
@{
Layout = null;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>has</title>
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" />
<link href="css/custom_styles.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="_content/AntDesign/css/ant-design-blazor.css" rel="stylesheet" />
<link href="_content/Blazor.ContextMenu/blazorContextMenu.min.css" rel="stylesheet" />
<script src="_content/BlazorInputFile/inputfile.js"></script>
<script src="~/js/site.js"></script>
</head>
<body>
<app>
<component type="typeof(App)" …Run Code Online (Sandbox Code Playgroud) 我正在练习 Angular JWT 身份验证和授权。这是我的auth.interceptor.ts文件:
import { HTTP_INTERCEPTORS, HttpEvent } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { HttpInterceptor, HttpHandler, HttpRequest } from "@angular/common/http";
import { Observable } from "rxjs";
import { TokenStorageService } from "../services/token-storage.service";
const TOKEN_HEADER_KEY = "Authorization";
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor(private token:TokenStorageService) { }
intercept(req: HttpRequest, next:HttpHandler): Observable<any> {
let authReq = req;
const token = this.token.getToken();
if (token != null) {
authReq = req.clone({ headers: req.headers.set(TOKEN_HEADER_KEY, 'Bearer' + token) …Run Code Online (Sandbox Code Playgroud) angular ×3
angular11 ×2
asp.net-core ×2
blazor ×2
c# ×2
typescript ×2
javascript ×1
matplotlib ×1
python ×1
razor ×1