Help with combine 2 functions

Hello,

I would like to combine two functions, but I have difficulties with it.

I have the two functions:

  <script>
    function myFunction(x) {
     if (x.matches) { // If media query matches
       window.location.replace("http://somewhere.com");
    }else{
       window.location.replace("http://somewhere.com")
    }
    }
    
    var x = window.matchMedia("(max-width: 700px)")
    myFunction(x) // Call listener function at run time
    x.addListener(myFunction) // Attach listener function on state changes
  </script>

and:

<script>
var value = "Hello World";
// or overwrite value in your callback function ...
this.scope.action = function() { return value; }
</script>
<md-button ng-click="send({payload:action()})">
  Click me to send a hello world
</md-button>

So how I can send Hello World from my dashboard template when the size of the screen change??
If I add send({payload:action()}) to my if query, it doestn work. I just dont get how to send any msg, when something happens. The example with button is good, but its html, ho to do this with javascript inside dashboard template node?

untested (but should point you in the right direction)...


<script>
(function(scope) {

    function myFunction(x) {
        scope.send({payload:"hello world"});
    }
    
    var x = window.matchMedia("(max-width: 700px)")
    myFunction(x) // Call listener function at run time
    x.addListener(myFunction) // Attach listener function on state changes

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

<md-button ng-click="send({payload:'hello world'})">
  Click me to send a hello world
</md-button>

exactly what I was looking for. Thank you very much! you saved my day :smiley:

scope.send was what I was missing. I tried everything.send but nothing worked.

I wonder why I cant use it in head section. Its need to be a widget inside a group. Do you have an idea?

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