在初始化angular6的下拉列表时,会引发错误
ERROR TypeError: Cannot set property 'tabIndex' of null
at n.value (materialize.min.js:6)
at new n (materialize.min.js:6)
at Function.value (materialize.min.js:6)
at Function.value (materialize.min.js:6)
at NavHeaderComponent.push../src/app/components/headers/nav-header/nav-header.component.ts.NavHeaderComponent.ngOnInit (nav-header.component.ts:24)
at checkAndUpdateDirectiveInline (core.js:9250)
at checkAndUpdateNodeInline (core.js:10514)
at checkAndUpdateNode (core.js:10476)
at debugCheckAndUpdateNode (core.js:11109)
at debugCheckDirectivesFn (core.js:11069)
下面是我用来初始化它的代码
ngOnInit() {
const elems = document.querySelectorAll('.dropdown-trigger');
const instances = M.Dropdown.init(elems);
}
答案 0 :(得分:0)
将此放在顶部:
从'materialize-css / dist / js / materialize'导入*作为M;
答案 1 :(得分:0)
使用 id 选择器代替类选择器。例如这样的呼叫下拉列表:
js:
ngOnInit() {
const elems = document.querySelectorAll('#dropdownId');
const instances = M.Dropdown.init(elems);
}