Search code examples
angularjsiotnode-red

How to pass message from angular template node in node red


I'm trying to pass input textbox value by clicking on button

<script>

var h = this.scope.myHot;
//var c = {{cold}};
var value = h;
// or overwrite value in your callback function ...
this.scope.action = function() { return value; }

</script>
<p>Hot: <input type="text" ng-model="hot" ng-value="myHot"></p>
<p>Cold: <input type="text" ng-model="cold"></p>
<md-button ng-click="send({payload:action()})">
    Click me
</md-button>

the message is always undefined


Solution

  • If you simply want to sent the angular model values back to your node-red flow, you can use a ui_template node with some generic ng code like this:

    <p>Hot: <input type="text" ng-model="myHot"></p>
    <p>Cold: <input type="text" ng-model="myCold"></p>
    <md-button ng-click="send({payload: {hot: myHot, cold: myCold}})">
        Send values
    </md-button>
    

    The returned msg.payload object will contains whatever values were entered into the hot and cold input fields, with this structure:

    {"hot":"123","cold":"4.5"}