How to store a msg.payload in a script variable inside a red ui_template node?

I wrote this code but it doesn't work

   <script type = "text/javascript">

        var msg = {{msg.payload}}

   </script>

this method considers the value {{msg.payload}} as an error due to the '{' in the syntax, I tried different ways, but nothing works, I guess I'm missing something I don't understand, please I'm open to any suggestions.

There is a code example on the ui_template's help tab of how to properly watch and
receive a msg in javascript.

<script>
(function(scope) {
  scope.$watch('msg', function(msg) {
    if (msg) {
      // Do something when msg arrives
     // ...
    }
  });
})(scope);
</script>
1 Like

And more extensive examples elsewhere.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.