0
votes

I'm trying to make a custom widget on Thingsboard that would change the text when it's pressed. Like this: Custom Widget creation

But it's not working at all. What am I doing wrong?

1
Please don't post your code in images. Post it as code so we can copy it. Please don't link to external images. Insert images directly into your post.lupz

1 Answers

0
votes

Did you read the official widgets development guide?

There are some examples that use click-events

https://thingsboard.io/docs/user-guide/contribution/widgets-development/#static-widget

Thingsboard uses AngularJS, so you can bind click-handlers to elements with the ng-click attribute like this:

<p id="text" ng-click="changeText()">Text</p>

To make this work you will need to create that click-handler in the widget's scope. The perfect place to do this is the onInit() method of the widget.

self.onInit = function() {
    self.ctx.$scope.changeText = function() {
        // change your text here
    };
};