在应用外访问 Polymer paper-toast class
Access Polymer paper-toast outside the app class
我有一个项目,我需要从扩展聚合物元素
的 ES6 应用 class 外部访问 ID 为 toastNewVersion
的 paper toast
class WascApp extends Polymer.Element {
_buttonOnTap() {
this.$.toastNewVersion.open();
}
正如预期的那样,这段代码工作正常。但我想在基本 <script>
标签中从这个 class 外部打开吐司。
我尝试使用 getElementById
document.getElementsByTagName('#toastNewVersion').open();
但是这个对象只是等于 null 而不是 toast。
任何想法,如何打开吐司?
谢谢!
聚合物 2 顺便说一句
其实我自己找到了方法
这会从 index.html 文件中打开一个普通的 paper-toast,如果 toast 在 app-element
s shadow-root 中:
document.querySelector('app-element').shadowRoot.querySelector('#toastNewVersion').open();
我有一个项目,我需要从扩展聚合物元素
的 ES6 应用 class 外部访问 ID 为toastNewVersion
的 paper toast
class WascApp extends Polymer.Element {
_buttonOnTap() {
this.$.toastNewVersion.open();
}
正如预期的那样,这段代码工作正常。但我想在基本 <script>
标签中从这个 class 外部打开吐司。
我尝试使用 getElementById
document.getElementsByTagName('#toastNewVersion').open();
但是这个对象只是等于 null 而不是 toast。
任何想法,如何打开吐司? 谢谢!
聚合物 2 顺便说一句
其实我自己找到了方法
这会从 index.html 文件中打开一个普通的 paper-toast,如果 toast 在 app-element
s shadow-root 中:
document.querySelector('app-element').shadowRoot.querySelector('#toastNewVersion').open();