1

I have a Webprojekt with FireBaseCloudMessaging running. Now i have to call a Method in a Typescript File to reload the Messages on Notification. Is this Possible?

HTML Part (index.html)

<script src="https://www.gstatic.com/firebasejs/4.3.0/firebase.js"></script>
<script>
    messaging.onMessage(function(payload) {
        console.log("Message received. ", payload);
        // ChatDialog.reloadMessages(); <-- Here i have to call the Typescript Method
    });
</script>

ChatDialog.ts

//This is the Method i have to call!
    reloadMessages(){
        this.messages.removeAll();
        localStorage.clear();
        ChatFunctions.getMessages(this, this.partner_id);
    }
mpromonet
  • 11,326
  • 43
  • 62
  • 91
Tim
  • 245
  • 3
  • 6
  • 18
  • How are you compiling your TS code? Do you use modules? Post your `tsconfig.json`? – Saravana Oct 06 '17 at 08:29
  • Iam using **NPM** and **Bower**! Iam compiling my Typescript whit **grunt**! HTML to Typescript is handled whit **Knockout** and Typescript to HTML via **JQuery and Ajax** – Tim Oct 06 '17 at 08:37
  • Typescript is compiled to JS, so it's definitely possible – just like calling any method in JS. This might help you to find your way around: https://stackoverflow.com/questions/26427722/calling-properly-typescript-code-from-javascript – helb Oct 06 '17 at 08:46
  • When iam calling it `new ChatDialog().reloadMessages()` it throws an error: `Error: You cannot apply bindings multiple times to the same element.`. – Tim Oct 06 '17 at 08:59

0 Answers0