jackocnr / intl-tel-input

A JavaScript plugin for entering and validating international telephone numbers
https://intl-tel-input.com
MIT License
7.54k stars 1.94k forks source link

setNumber not setting the phone Number #1576

Closed juvegitau closed 4 months ago

juvegitau commented 4 months ago

Steps to reproduce

  1. Create angular js directive
  2. Intialize the intelTelInput
  3. setNumber see code below

Expected behaviour

when i call getNumber() i expect to get the phone number

import intlTelInput from 'intl-tel-input'; (function () { 'use strict';

angular.module('estimate') .directive('intlTelInput', ["$timeout", function ($timeout) { return { restrict: 'A', require: 'ngModel', link: function (scope, elm, attr, ctrl) { $timeout(function () { //ctrl.$validate(); }); var options = { initialCountry: 'ke', preferredCountries: ['ke', 'ug', 'tz'], showFlags: false, utilsScript: "/scripts/app-build/utils.js" } var inputElement = elm[0]; debugger var iti = intlTelInput(inputElement, options); ctrl.$validators.ngIntlTelInput = function (value) { var sss = iti.getNumber();

          if (value) {
            return iti.isValidNumber();;

          } else {
            return true;
          }
        };

        ctrl.$parsers.push(function (value) {
          return iti.getNumber();;

        });
        ctrl.$formatters.push(function (modelValue) {

          iti.setNumber(modelValue);

          return modelValue;
        });

      }
    };
  }]);

})();