如果您想了解获取TypeError:这不是在Mocha中使用Buffer.from的类型化数组的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析angular–使用hasError()进行验证的
如果您想了解获取TypeError:这不是在Mocha中使用Buffer.from的类型化数组的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析angular – 使用hasError()进行验证的表单生成器抛出错误ERROR TypeError:无法读取未定义的属性’hasError’、create_string_buffer抛出错误TypeError:预期的str / bytes而非str实例、ERROR TypeError: control.registerOnChange 不是动态添加组件时的函数、how-to-check-references-for-buffers-provided-from-a-pooledbytebufallocator的各个方面,并给出实际的案例分析,希望能帮助到您!
本文目录一览:- 获取TypeError:这不是在Mocha中使用Buffer.from的类型化数组
- angular – 使用hasError()进行验证的表单生成器抛出错误ERROR TypeError:无法读取未定义的属性’hasError’
- create_string_buffer抛出错误TypeError:预期的str / bytes而非str实例
- ERROR TypeError: control.registerOnChange 不是动态添加组件时的函数
- how-to-check-references-for-buffers-provided-from-a-pooledbytebufallocator
获取TypeError:这不是在Mocha中使用Buffer.from的类型化数组
我正在使用Mocha / Chai对一个库进行单元测试,该库最近开始使用nodejs的Buffer对象解决另一个问题。
我在单元测试中收到以下错误消息:
TypeError: this is not a typed array. at Function.from (native) at Object.hashesMatch (index.js:29:18at Context.<anonymous> (test/test.js:25:22)
index.js的第29行是我使用nodejs的Buffer …的地方
var b = Buffer.from (''some string or other'');
我找不到polyfill或变通办法,因此非常感谢您的建议。
谢谢
答案1
小编典典您可能正在使用旧版本的Node.js。
Buffer.from
在6.0.0版中引入:
为了使Buffer对象的创建更可靠且更不易出错,新的Buffer()构造函数的各种形式已被弃用,并由单独的Buffer.from(),Buffer.alloc()和Buffer.allocUnsafe()方法代替。
在早期版本的文档中没有引用此方法。
您可以更新到6.0.0,也可以使用不推荐使用的构造函数API,该API具有以下签名:
new Buffer(str[, encoding])
angular – 使用hasError()进行验证的表单生成器抛出错误ERROR TypeError:无法读取未定义的属性’hasError’
在component.ts中,我使用formGroup实现了我的表单
以下是我的代码
public myForm: FormGroup; constructor(private authenticateservice: AuthenticateService,private _fb: FormBuilder ) { } ngOnInit() { this.myForm = this._fb.group({ address: [this.userDetails.address,[<any>Validators.required]],address2: ['',city: ['',company_address: ['',company_address2: ['',company_city: ['',company_country: ['',company: ['',[<any>Validators.required,Validators.minLength(3)] ],company_tax_number: ['',company_zip: ['',Validators.minLength(5),Validators.maxLength(7)]],country: ['',email: ['',Validators.email]],first_name: [this.userDetails.first_name,id: ['',last_name: ['',phone: ['',Validators.minLength(10)]],zip: ['',user_type: ['2',terms: [0,hash_tag: [''],}); }
它工作正常.但是在frontEnd中显示验证时
我这样用过
<div> <div> <label>Address 2</label> <textareaplaceholder="Address" rows="2" [readonly]="disabled" id="companyaddress2" formControlName="company_address2"></textarea> <span*ngIf="myForm.controls['company_address2'].hasError('required')">Company Address 2 is required.</span> </div> </div>
它正在工作,但在控制台中抛出错误,如下
错误TypeError:无法读取未定义的属性’hasError’
请帮我解释一下这个问题.
谢谢.
<span*ngIf="myForm.controls['company_address2'].errors?.required && myForm.controls['company_address2'].touched">Company Address 2 is required </span>
create_string_buffer抛出错误TypeError:预期的str / bytes而非str实例
我正在尝试这个简单的ctypes示例,并得到提到的错误
>>> from ctypes import create_string_buffer>>> str = create_string_buffer("hello")Traceback (most recent call last):File "<stdin>", line 1, in <module>File "C:\Python32\lib\ctypes\__init__.py", line 59, in create_string_bufferbuf.value = initTypeError: str/bytes expected instead of str instance
有人知道我在做什么错吗?
同样,我试图从我的python代码中将指向字符串的指针传递给C函数,以便可以在那里执行一些字符串操作并返回另一个字符串。有人可以给我一些示例代码吗?
extern "C" __declspec(dllexport) char * echo(char* c){ // do stuff return c;}
答案1
小编典典关于使其正常工作,如果您将其传递给bytes
对象,它将起作用:
>>> import ctypes>>> ctypes.create_string_buffer(b''hello'')<ctypes.c_char_Array_6 object at 0x25258c0>
查看以下代码create_string_buffer
:
def create_string_buffer(init, size=None): """create_string_buffer(aBytes) -> character array create_string_buffer(anInteger) -> character array create_string_buffer(aString, anInteger) -> character array """ if isinstance(init, (str, bytes)): if size is None: size = len(init)+1 buftype = c_char * size buf = buftype() buf.value = init return buf elif isinstance(init, int): buftype = c_char * init buf = buftype() return buf raise TypeError(init)
直接做
>>> (ctypes.c_char * 10)().value = b''123456789''
这很好。
>>> (ctypes.c_char * 10)().value = ''123456789''Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: str/bytes expected instead of str instance
这表明了相同的行为。在我看来,好像您已找到一个错误。
是时候访问http://bugs.python.org了。有一些与相关的bugc_char
,create_string_buffer
它们都在同一领域,但是没有人报告说str
现在给它失败了(但是有明确的例子表明它曾经在Py3K中工作)。
ERROR TypeError: control.registerOnChange 不是动态添加组件时的函数
如何解决ERROR TypeError: control.registerOnChange 不是动态添加组件时的函数?
条件
条件组件:动态添加该组件
规则组件:这将承载条件组件
问题
点击添加条件按钮添加条件表单后,屏幕无法正确呈现。当我检查控制台时出现以下错误
easyrules.component.html:95 ERROR TypeError: control.registerOnChange is not a function
at setUpModelChangePipeline (forms.js:2387)
at setUpControl (forms.js:2323)
at FormGroupDirective.addControl (forms.js:5492)
at FormControlName._setUpControl (forms.js:6070)
at FormControlName.ngOnChanges (forms.js:6001)
at checkAndUpdateDirectiveInline (core.js:23630)
at checkAndUpdateNodeInline (core.js:30787)
at checkAndUpdateNode (core.js:30749)
at debugCheckAndUpdateNode (core.js:31376)
at debugCheckDirectivesFn (core.js:31340)
附上来自 html 和组件的以下代码片段。
规则组件 Html:
<ng-container formArrayName="conditions">
<app-easyrulecondition *ngFor="let c of _conditionsFormArray?.controls; index as j"
(remove)="removeCondition(j)"
[formControlName]="j"
[formlabel]="''Condition '' + (j+1)"
[jsonTemplateData]="jsonTemplateData"
[isEditMode]="isEditMode">
</app-easyrulecondition>
条件 HTML 和 TS:
<form [formGroup]="form">
<fieldset>
<legend>{{formlabel}}</legend>
<div fxLayout="row" fxLayoutAlign="space-between">
<mat-form-field appearance="fill">
<mat-label>Select</mat-label>
<mat-select formControlName="name" (selectionChange)="refreshList($event)" required [disabledControl]="isEditMode">
<mat-option *ngFor="let item of templateJsonLevel.data" [value]="item" >{{item}}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="fill">
<mat-label>Select</mat-label>
<mat-select formControlName="property" required [disabledControl]="isEditMode">
<mat-option *ngFor="let item of templateJsonLevel2.data" [value]="item" >{{item}}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="fill">
<mat-label>Opertaor</mat-label>
<mat-select formControlName="operator" (selectionChange)="updateValueOnoperatorChange($event)" required [disabledControl]="isEditMode">
<mat-option value="eq">EQUAL</mat-option>
<mat-option value="in">IN</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="fill">
<input matInput (focusout)="updateValueBasedOnoperatorChange($event)" formControlName="value" maxlength="100" required [disabledControl]="isEditMode"/>
</mat-form-field>
<button mat-button color="primary" (click)="remove.emit()" [disabled]="isEditMode">
<mat-icon>delete</mat-icon></button>
</div>
<!-- </div> -->
</fieldset>
export interface EasyruleconditionComponentData {
name: string;
property: string;
operator: string;
value: string;
}
export class EasyruleconditionComponent implements ControlValueAccessor,OnDestroy,OnInit,AfterViewInit {
@input()
formlabel: string | number = ''Condition'';
@Output()
remove: EventEmitter<void> = new EventEmitter<void>();
form: FormGroup;
@input()
jsonTemplateData: any;
@input()
isEditMode: boolean;
private _onChange: (
value: EasyruleconditionComponentData | null | undefined
) => void;
private _destroy$: Subject<void> = new Subject<void>();
templateJsonLevel = { data: [] };
templateJsonLevel2 = { data: [] };
temp: Observable<any[]> = new Observable<any[]>();
constructor(private _fb: FormBuilder,private apiService: ApiService,private cdr: ChangeDetectorRef) { }
ngOnInit(): void {
this._createFormGroup();
this._setupObservables();
}
ngAfterViewInit(): void {
this.cdr.detectChanges();
}
ngOnDestroy(): void {
if (this._destroy$ && !this._destroy$.closed) {
this._destroy$.next();
this._destroy$.complete();
}
}
writeValue(value: EasyruleconditionComponentData): void {
if (!value) {
return;
}
this.form.patchValue(value);
}
registerOnChange(
fn: (v: EasyruleconditionComponentData | null | undefined) => void
): void {
this._onChange = fn;
}
registerOnTouched(fn: any): void {
// Todo: implement this method
// throw new Error(''registerOnTouched not implemented'');
}
setdisabledState(isdisabled: boolean): void {
// Todo: implement this method
// throw new Error(''setdisabledState not implemented'');
}
private _createFormGroup(): void {
this.form = this._fb.group({
name: ['''',Validators.required],property: ['''',operator: ['''',value: ''''
});
}
private _setupObservables(): void {
this.form.valueChanges.pipe(takeuntil(this._destroy$)).subscribe(value => {
if (this._onChange) {
this._onChange(value);
}
});
}
}
Attached screen
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
how-to-check-references-for-buffers-provided-from-a-pooledbytebufallocator
Using Netty 4, is there a way to see how many ByteBuf''s are unreleased (still allocated) from a PooledByteBufAllocator?
The reason I''m looking for this is mainly for unit testing, so that I can provide a PooledByteBufAllocator into a handler/pipeline on the channel (using an EmbeddedChannel), and ensure that after the handler or pipeline completes that all requested/created pooled ByteBufs have been released.
今天关于获取TypeError:这不是在Mocha中使用Buffer.from的类型化数组的介绍到此结束,谢谢您的阅读,有关angular – 使用hasError()进行验证的表单生成器抛出错误ERROR TypeError:无法读取未定义的属性’hasError’、create_string_buffer抛出错误TypeError:预期的str / bytes而非str实例、ERROR TypeError: control.registerOnChange 不是动态添加组件时的函数、how-to-check-references-for-buffers-provided-from-a-pooledbytebufallocator等更多相关知识的信息可以在本站进行查询。
本文标签: