How To Store A Msg.payload Into A Script Variable Inside A Ui_template Node Red?
I wrote this code but it doesn't work this method consider the {{msg.payload}} va
Solution 1:
The Dashboard UI node uses Angular for it's templating so you need do things a little differently.
A good example can be found here but basically something like this:
<script>
//console.dir(scope) // this also works
//console.dir(scope.msg) // This doesn't because scope.msg doesn't yet exist
// Lambda function to access the Angular Scope
;(function(scope) {
//console.log('--- SCOPE ---')
//console.dir(scope) // this works but you only get it once (on startup)
//console.dir(scope.msg) // Doesn't work for because scope.msg doesn't yet exist
//Have to use $watch so we pick up new, incoming msg's
scope.$watch('msg.payload', function(newVal, oldVal) {
console.log('- Scope.msg -')
console.dir(scope.msg)
})
})(scope)
</script>
Post a Comment for "How To Store A Msg.payload Into A Script Variable Inside A Ui_template Node Red?"