简体   繁体   English

无法使用 querySelector/getElementById 获取 md-dialog 的子元素

[英]Cannot get the child element of md-dialog using querySelector/getElementById

How can I get the child element of <md-dialog> using the element's id?如何使用元素的 id 获取<md-dialog>的子元素?

Here are the following workaround I did:以下是我所做的以下解决方法:

console.log(document.getElementById('input-file-upload')); // returns null
console.log(document.querySelector('#input-file-upload')); // returns null

But it returns null please see this demo但它返回null请看这个演示

You need to wait until the modal is open.您需要等到模态打开。 If you put your code inside a $timeout it works.如果你把你的代码放在$timeout里面,它就可以工作。

$timeout(function(){
    // HERE is the Problem i cannot get input file element by queryselector/getElementById
    console.log(document.getElementById('input-file-upload')) // returns null
    console.log(document.querySelector('#input-file-upload')) // returns null
});

Alternatively, you can use the onComplete property of $mdDialog.或者,您可以使用 $mdDialog 的onComplete属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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