Question

I'm trying to use the Google Javascript library liibphonenumber to return a sample number given a region code.

I'm calling it in a block in a JSP file:

<script>
i18n.phonenumbers.PhoneNumberUtil.getExampleNumber("NL");
</script>

The error returned is:

Uncaught TypeError: Object function () {
  /**
   * A mapping from a region code to the PhoneMetadata for that region.
   * @type {Object.<string, i18n.phonenumbers.PhoneMetadata>}
   */
  this.regionToMetadataMap = {};
} has no method 'getExampleNumber' 

I've included at the top of the JSP:

<script type="text/javascript" src="/javascript/goog/base.js"></script>
<script>
    goog.require('goog.proto2.Message');
</script>
<script type="text/javascript" src="/javascript/phonemetadata.pb.js"></script>
<script type="text/javascript" src="/javascript/phonenumber.pb.js"></script>
<script type="text/javascript" src="/javascript/metadata.js"></script>
<script type="text/javascript" src="/javascript/phonenumberutil.js"></script>

And even tried putting

goog.require('i18n.phonenumbers.PhoneNumberUtil');

in the same script block as the call.

All help greatly appreciated!

Thanks.

Les

Was it helpful?

Solution

So this all boiled down to being a newbie JS developer. I needed to create an instance of the class 1st. That was basically what the error was telling me - just didn't realize it until I did some more net searching.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top