[英]How to disable change value in ngModel
I've got component of in Angular 5 - trying to build unit-test which check when it's disabled than impossible to set value to model of component. 我在Angular 5中有了组件-试图建立单元测试,以检查何时禁用它,而不是不可能为组件模型设置值。 And I don't know why - it's still possible to change.
而且我不知道为什么-仍然可以更改。
[(ngModel)]="value"
[attr.disabled]="disabled ? 'disabled' : null"
and test looks like this - and it's gave me error 测试看起来像这样-这给了我错误
it("DISABLED", async(() => {
component.disabled = true;
component.value = 'testtesttest';
fixture.detectChanges();
const htmlInputComponent: HTMLElement = fixture.nativeElement;
const inputValue = htmlInputComponent.querySelector('input').value;
expect(inputValue).toBeFalsy();
}));
Tried to add some rules in ngOnChange - but it still makes changes in value. 试图在ngOnChange中添加一些规则-但它仍然会改变值。
尝试-
[attr.disabled]="disabled ? true : null"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.