send msg from script in ui_template node

In my flow, I have this simple test array of object in input :

[
    {
        "name": "Pasta with pesto",
        "ingredients": [
            "pasta",
            "pesto"
        ]
    },
    {
        "name": "Pasta with butter",
        "ingredients": [
            "pasta",
            "butter"
        ]
    }
]

I want to display the different meals and their ingredients in a page (OK), but I also want to have a checkbox in front of each meal and a “validate” button in a way that the output of the ui_template node that display the page will also send back an array of the selected meals that have been check before the user clicked on the “validate” button.

Here is my actual code on the ui_template node :

<div ng-repeat="meal in msg.payload">
    <input type="checkbox" ng-model="meal.selected">
    <h2>{{meal.name}}</h2>
    <p>Ingredients: {{meal.ingredients.join(', ')}}</p>
    <hr>
</div>

<button ng-click="validate()">Validate</button>

<script>
    (function($scope) {
        function validate() {
            var mealsSelection = msg.payload.filter(function(meal) {
                return meal.selected;
            });
            $scope.send({ payload: mealsSelection});
        };
    })(scope);
</script> 

With this code I have nothing in output of the ui_template node when I click on the “validate” button after a selection, can you please tell me what is wrong with my code ?

Read more here: Source link