简体   繁体   中英

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. 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.

尝试-

[attr.disabled]="disabled ? true : null"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM