我想要一个按钮被禁用,直到使用FormBuilder for Angular检查复选框.我不想明确检查复选框的值,而是希望使用验证器,以便我可以简单地检查form.valid.
在下面的两个验证案例中,复选框都是
interface ValidationResult {
[key:string]:boolean;
}
export class CheckboxValidator {
static checked(control:Control) {
return { "checked": control.value };
}
}
@Component({
selector: 'my-form',
directives: [FORM_DIRECTIVES],
template: ` <form [ngFormModel]="form" (ngSubmit)="onSubmit(form.value)">
<input type="checkbox" id="cb" ngControl="cb">
<button type="submit" [disabled]="!form.valid">
</form>`
})
export class SomeForm {
regForm: ControlGroup;
constructor(fb: FormBuilder) {
this.form = fb.group({
cb: [ CheckboxValidator.checked ]
//cb: [ false, Validators.required ] <-- I have also tried this
});
}
onSubmit(value: any) {
console.log('Submitted: ', this.form);
} …Run Code Online (Sandbox Code Playgroud) 我是新手使用Google测试框架进行单元测试,并打算生成测试的XML报告或命令输出作为报告(我可以显然打印它).我已阅读有关生成XML报告的信息,但未能清楚地了解如何生成报告.任何帮助将不胜感激.
干杯.
在我说一句话之前,让我感谢社区作为我最近编程查询的权威位置.并假装那些称赞不是用文字表达的.无论如何,概率定律指出我偶然发现了使用多功能搜索栏找不到的东西,所以我决定第一次明确要求.也许我只是没有使用Pythonic-enough语言进行搜索.或许我在Googling/Stackoverflowing吮吸.而不管...
我正在玩Python协同程序和生成器.从我可以收集到的,你可以做任何生成器理解可以与生产者协同程序,尽管更冗长.我目前正在使用Python 3,尽管有关Python 2的任何答案都不会错过.
所以我假设以下代码片段是等价的:
one_to_three = (num for num in range(1, 4))
Run Code Online (Sandbox Code Playgroud)
...
def one_to_three():
for num in range(1, 4):
yield num
one_to_three_gen = one_to_three()
Run Code Online (Sandbox Code Playgroud)
它适用于我的Python安装.如果我忽略该代码中的冗余 - 如此常见的示例,我看到生成器理解很容易映射到生成器协同程序生成的生成器.作为Pragmatic博士,我尝试将相同的概念映射到dicts,因为dict理解已经存在,我认为这两个是等价的:
one_to_three_doubles = {num : num * 2 for num in range(1, 4)}
Run Code Online (Sandbox Code Playgroud)
...
def one_to_three_doubles():
for num in range(1, 4):
yield num : num * 2
one_to_three_doubles_gen = one_to_three_doubles()
Run Code Online (Sandbox Code Playgroud)
第一个可以工作,但第二个没有.它标记第3行冒号上的语法错误.
现在,要么我在语法上略微下滑,要么我对生产者协程如何工作有很大的误解.我怀疑它的失败是因为你不能让coroutine返回列表而不是生成器,但我真的不知道.
所以是的,修正这个错误基本上就是我所要求的; 提前致谢.我更喜欢一个答案,告诉我答案,而不是给我一个全新的方法来实现结果,但显然如果这是唯一的方法......
在ASP.NET Core 1.0中,每个响应都将包含标头Server: Kestrel.我想删除此标头以及其他标头,如X-Power-By使用中间件.
我知道我们可以通过设置以下内容来删除主机配置中的Kestrel标头,但我想使用中间件(实际上当我们有Httpmodule时我们可以这样做,所以我学习同样的事情).我试了一下它没用.
new WebHostBuilder()
.UseKestrel(c => c.AddServerHeader = false)
Run Code Online (Sandbox Code Playgroud)
试过的代码:
public class HeaderRemoverMiddleware
{
private readonly RequestDelegate _next;
public HeaderRemoverMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext httpContext)
{
httpContext.Response.OnStarting(callback: removeHeaders, state: httpContext);
await _next.Invoke(httpContext);
}
private Task removeHeaders(object context)
{
var httpContext = (HttpContext)context;
if (httpContext.Response.Headers.ContainsKey("Server"))
{
httpContext.Response.Headers.Remove("Server");
}
return Task.FromResult(0);
}
}
public static class HeaderRemoverExtensions
{
public static IApplicationBuilder UseServerHeaderRemover(this IApplicationBuilder builder)
{
return builder.UseMiddleware<HeaderRemoverMiddleware>();
}
}
Run Code Online (Sandbox Code Playgroud) .net-core asp.net-core asp.net-core-1.0 asp.net-core-middleware
我正在尝试制作一个基本的语音识别助手。当我运行代码时,它告诉我:
Traceback (most recent call last):
File "C:\Users\Mo.haytham\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 108, in get_pyaudio
import pyaudio
ModuleNotFoundError: No module named 'pyaudio'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Mo.haytham/.PyCharmCE2018.3/config/scratches/ALPHA_BASIC.py", line 22, in <module>
hear()
File "C:/Users/Mo.haytham/.PyCharmCE2018.3/config/scratches/ALPHA_BASIC.py", line 13, in hear
with sr.Microphone() as sourse:
File "C:\Users\Mo.haytham\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 79, in __init__
self.pyaudio_module = self.get_pyaudio()
File "C:\Users\Mo.haytham\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 110, in get_pyaudio
raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation
Run Code Online (Sandbox Code Playgroud)
我尝试过, …
我有一个分支feature/xyz-functionality,我想与develop分支合并。我是在 3 天前创建的,我没有合并的权限。
另一方面,我的团队负责人忙于其他事情,在此期间我编写了更多需要推送的脚本,因为我创建了合并请求,我害怕推送提交。
那么什么是好的做法,我应该推动提交呢?我可以吗?或者我应该创建新分支然后推送它?
请指导我,我将不胜感激。非常感谢。
我有图像,如下所示:
我想找到 8 位数字的边界框。我的第一次尝试是使用 cv2 和以下代码:
import cv2
import matplotlib.pyplot as plt
import cvlib as cv
from cvlib.object_detection import draw_bbox
im = cv2.imread('31197402.png')
bbox, label, conf = cv.detect_common_objects(im)
output_image = draw_bbox(im, bbox, label, conf)
plt.imshow(output_image)
plt.show()
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用。有人有想法吗?
我想出了以下查询,解决起来并不那么具有挑战性,但我仍然认为可能有更好的方法。有什么建议吗?
我有下表:
tb_Salary
EmpID DeptID Salary
---------------------
1 1 20000
2 1 20000
3 2 30000
4 2 800
5 2 200
Run Code Online (Sandbox Code Playgroud)
我想将员工的工资增加卢比。1000只在部门平均工资超过35000的时候。
这可以使用单个更新查询吗?
我按照以下方式做到了这一点。但似乎这不是那么聪明的解决方案。
UPDATE tb_Salary t1
SET t1.Salary=t1.Salary+1000
WHERE 35000 < (select AVG(t2.Salary) from tb_Salary t2 WHERE t2.DeptID=t1.DeptID)
Run Code Online (Sandbox Code Playgroud) 我有两个QByteArray,sData而且dData.
我要复制n从位置字节x中dData,即&dData[x]以位置y的sData即&sData[y].
在C中,数组副本由.完成 memcpy(&dData[x], &sData[y], n);
如何复制以上数据QByteArray在Qt中完成?
我目前想知道如何合理地使用QObject::destroyed(QObject*) 信号.
我注意到 - QWidget衍生物体的处理略有不同.考虑以下小型自包含和编译示例:
/* sscce.pro:
QT += core gui widgets
CONFIG += c++11
TARGET = sscce
TEMPLATE = app
SOURCES += main.cpp
*/
#include <QApplication>
#include <QPushButton>
#include <QTimer>
#include <QtDebug>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QPushButton *button = new QPushButton;
QObject::connect(button, &QPushButton::destroyed,
[=](QObject *o) { qDebug() << o; });
delete button;
QTimer *timer = new QTimer;
QObject::connect(timer, &QTimer::destroyed,
[=](QObject *o) { qDebug() << o; });
delete timer;
return app.exec(); …Run Code Online (Sandbox Code Playgroud) python ×3
qt ×2
.net-core ×1
angular ×1
asp.net-core ×1
c++ ×1
dictionary ×1
generator ×1
git ×1
googletest ×1
ocr ×1
opencv ×1
pyaudio ×1
python-3.x ×1
qbytearray ×1
report ×1
sql ×1
unit-testing ×1
visual-c++ ×1
xml ×1