Thassa February 2016

How can I get my script to execute on a textbox input change in AngularJS?

I'm using the Farbtastic color picker to change values in an HTML input text box. I have it programmed so that when the hex value inside the text box is changed, it is supposed to execute a JavaScript function that converts the hex value to RGB and sends it to a device that changes the color of an LED light. I've successfully tested this using a button to perform the script, so I'm fairly certain that the function isn't the problem

Here's the relevant HTML code:

<div id="colorpicker"></div>
        <md-input>
            <md-input-container>
                <label>Color</label>
                <input type="text" id="color" name="color" value="#123456" ng-model="color" ng-change="return hexToRGB(document.getElementById('color').value);"/>
            </md-input-container>
        </md-input>

The ng-change seems to be the root of the issue. Is there something I need to change here? Or is there something else that needs to be fixed?

Answers


Raphael Rafatpanah February 2016

Remove the return keyword.

Change:

ng-change="return hexToRGB(document.getElementById('color').value);"

To:

ng-change="hexToRGB(document.getElementById('color').value);"

Post Status

Asked in February 2016
Viewed 2,904 times
Voted 13
Answered 1 times

Search




Leave an answer