Hey everyone, I'm currently working with the Angular UI Mask directive. Specifically, I am using the filter for hours '99:99'.
My approach involves grabbing the ng-model of the input box, converting it to a string, looping through the string, and adding a colon ":" after the second position before returning the formatted string. However, despite my efforts, the result returned from the function seems correct to some extent.
For example, if I enter 1212 in the input box, due to the UI mask, it will display as 12:12 in the box. But when I call the function, it returns as 12:12undefined... Can anyone assist me with this issue?
Here's the code snippet:
<div ng-controller="MyCtrl">
<input type="text" ui-mask="'99:99'" ng-model="time">{{ time }}
<br>{{ convert(time) }}
</div>
JS file:
function MyCtrl($scope) {
$scope.time = '';
$scope.convert = function (input) {
var str = input + '';
var counter = 0;
var newStr = '';
while (counter <= str.length) {
if (counter === 2)
newStr += ':';
newStr += str[counter];
counter++;
}
return newStr;
}