3

template

 <ng-multiselect-dropdown #Name [placeholder]="'Name'" [data]="data" 
    formControlName="name" [settings]="myNameTexts"(onDeSelectAll)="onNameDeSelect($this)"> 
  </ng-multiselect-dropdown>

component

 document.getElementById("#Name").disabled= false
1
  • // in HTML : <ng-multiselect-dropdown #Name [placeholder]="'Name'" [data]="data" formControlName="name" [settings]="myNameTexts" (onDeSelectAll)="onNameDeSelect($this)"> </ng-multiselect-dropdown> Commented Aug 27, 2019 at 9:49

4 Answers 4

3

Should be more like:

<ng-multiselect-dropdown [disabled]="isDropdownDisabled" ...> 
  </ng-multiselect-dropdown>

and in control:

public isDropdownDisabled = false;

someMethod() {
  this.isDropdownDisabled = true;
}
Sign up to request clarification or add additional context in comments.

8 Comments

I already did that but I don't like it , because you will get warning message in the control , the author of this library does not implement control accessor interface correctly
Is this the one you're using github.com/NileshPatel17/ng-multiselect-dropdown/blob/master/… ? I don't get what the problem is...
whebn you are using reactive form any change on the form control will reflect to the component automatickly like disable but in here there is a bug check this demo stackblitz.com/edit/angular-hw8ugk
this this.form.get('name').disable() should make the component as disabled without set the property in the template
@malbarmawi in that case you should pass disabled via the form control like here: stackblitz.com/edit/angular-auupgp?file=src/app/… That's not a bug with that control, it's because of your code since you are using the reactive forms approach
|
1

Try using

disabled="true"

It will disable your dropdown.

1 Comment

I mean dynamicaly, how to do it ?
1

Just use CSS property 'pointer-events: none' on your control.

2 Comments

@codowo was asking for a dynamic solution.
Yes, we can add style/classes dynamically too.
0

when you are use reactive forms you can disable any form control by he disable method of the from control like this

this.form.get('name').disable()

it 'is look like the author doesn't implement control accessor interface correctly in case you try to set the disabled property in the template ,while it will work but you will got a warning

It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true when you set up this control in your component class, the disabled attribute will actually be set in the DOM for you. We recommend using this approach to avoid 'changed after checked' errors.

Example: form = new FormGroup({ first: new FormControl({value: 'Nancy', disabled: true}, Validators.required), last: new FormControl('Drew', Validators.required) });

this just work around this bug so to keep the disable value base of the form control we can you disabled property base of the form control disable value

component

  get disabled() {
    return this.myForm.get('city').disable
  }

template

    <form [formGroup]="myForm">
        <ng-multiselect-dropdown
            name="city"
            [placeholder]="'Select City'"
            [data]="cities"
            formControlName="city"
            [disabled]="disabled"
            [settings]="dropdownSettings"
            (onSelect)="onItemSelect($event)">
        </ng-multiselect-dropdown>
   </form>

demo 🔥🔥

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.