如何在Typescript中动态禁用或启用ng-multiselect-dropdown

时间:2019-08-27 09:49:09

标签: angular typescript getelementbyid

模板

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

组件

 document.getElementById("#Name").disabled= false

4 个答案:

答案 0 :(得分:2)

应该更像是:

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

并处于控制状态:

public isDropdownDisabled = false;

someMethod() {
  this.isDropdownDisabled = true;
}

答案 1 :(得分:1)

尝试使用

disabled="true"

它将禁用您的下拉菜单。

答案 2 :(得分:0)

当您使用反应性表单时,您可以通过禁用from控件的方法来禁用任何表单控件

Traceback (most recent call last):
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
    chunked=chunked)
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 344, in _make_request
    self._validate_conn(conn)
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 843, in _validate_conn
    conn.connect()
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connection.py", line 370, in connect
    ssl_context=context)
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 355, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 853, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
OSError: [Errno 0] Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 641, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/util/retry.py", line 368, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
    chunked=chunked)
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 344, in _make_request
    self._validate_conn(conn)
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 843, in _validate_conn
    conn.connect()
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/connection.py", line 370, in connect
    ssl_context=context)
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 355, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 853, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: ('Connection aborted.', OSError(0, 'Error'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/kyungmin/PycharmProjects/untitled14/a.py", line 11, in <module>
    req = requests.get(url, headers=headers)
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/Users/kyungmin/PycharmProjects/untitled14/venv/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', OSError(0, 'Error'))

Process finished with exit code 1

“如果您尝试在模板中设置disabled属性,似乎作者没有正确实现控件访问器接口,虽然它可以工作,但会收到警告

  

您似乎正在使用带有反应形式的Disabled属性   指示。如果您在   您的组件类,disable属性实际上将在   您的DOM。我们建议您使用这种方法来避免“更改   检查后的错误。

     

示例:form = new FormGroup({首先:new FormControl({value:   'Nancy',已禁用:true},Validators.required),最后一个:new   FormControl('Drew',Validators.required)});

这只是解决此错误的方法,因此为了保持表单控件的禁用值基础,我们可以禁用表单控件禁用值的属性基础

组件

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

模板

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

demo ??

答案 3 :(得分:0)

只需在控件上使用CSS属性'pointer-events:none'。