I was unable to find the answer to quite a simple question (I would guess).
Having template with multiple {{variables}}
, I would expect to update only ones with passed value but it looks like the whole template is being updated on every incoming message?
Here is simple example:
[{"id":"d9f359da.f5c4a8","type":"inject","z":"45969c2d.16dd0c","name":"","topic":"","payload":"a","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":80,"wires":[["4aa71fcb.043c68"]]},{"id":"bc12f616.498778","type":"inject","z":"45969c2d.16dd0c","name":"","topic":"","payload":"b","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":120,"wires":[["4aa71fcb.043c68"]]},{"id":"4aa71fcb.043c68","type":"function","z":"45969c2d.16dd0c","name":"","func":"if (msg.payload === 'a') {\n msg.a = 'received: a';\n}\nif (msg.payload === 'b') {\n msg.b = 'received: b';\n}\n// delete msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":100,"wires":[["e41b8150.b67e28","a2129493.4e3dd8"]]},{"id":"e41b8150.b67e28","type":"ui_template","z":"45969c2d.16dd0c","group":"21e4810e.d4dbe6","name":"","order":0,"width":"6","height":"6","format":"<div>\n <div>a: {{msg.a}}</div>\n <div>b: {{msg.b}}</div>\n</div>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":540,"y":100,"wires":[[]]},{"id":"a2129493.4e3dd8","type":"debug","z":"45969c2d.16dd0c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":530,"y":140,"wires":[]},{"id":"21e4810e.d4dbe6","type":"ui_group","z":"","name":"Test","tab":"fa232f71.167e7","order":1,"disp":true,"width":"6"},{"id":"fa232f71.167e7","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":3}]
having displayed a: "{{msg.a}}"
-> a: "foo"
and sending msg.b = 'bar'
, a
is removed from the display resulting in a: ""
.
I have quite big SVG drawing in my template. So in order to update one part of it I have to do one of the following?:
- store every variable in some context and always pass all variables in
msg
to the template - resign from using simple
{{msg.variable}}
and use uglyscope.$watch('msg', function(msg) {//search element and update its content
Both approaches looks much less pretty than just simple updating {{msg.variable}}
by sending msg.variable = 'new value';
to the template.