简体   繁体   English

如何从build / main.js内部的控制台访问函数

[英]how to access the function from console inside of build/main.js

I'm using ionic/Angular and I can't seem to have access to the functions that's inside of the webpack built js file. 我正在使用ionic / Angular,但似乎无法访问webpack构建的js文件内部的功能。 when I open chrome console and type in the function nothing happens.. I tried window.myfunction() in typescript but it didn't like the window. 当我打开chrome控制台并键入函数时,什么都没有发生。.我在打字稿中尝试了window.myfunction(),但它不喜欢该窗口。

What I've done to simulate push notifications is, in the constructor, exporting to the global window my App class 我所做的模拟推送通知的方法是,在构造函数中,将App类导出到全局窗口

export class MyApp {
  constructor(public platform: Platform) {
    window["myapp"] = this; //<-- export the class into window
  }

  onNotification(data) {
    //processNotification
  }
}

Then using the console I can simulate receiving a notification: 然后,使用控制台,我可以模拟接收通知:

window.myapp.onNotification({additionalData:{type:"test", foreground:true}, message:"This is the message"}) window.myapp.onNotification({additionalData:{type:“ test”,前景:true},消息:“这是消息”})

I hope it helps 希望对您有所帮助

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

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