I'm facing an issue with creating a provider in angularjs using es6 as it doesn't seem to be injected properly ($get is not being called). Check out the code snippet below:
export default class NgIntlTelInputProvider {
constructor() {
this.props = {};
this.setFn = (obj) => {
if (typeof obj === 'object') {
for (var key in obj) {
this.props[key] = obj[key];
}
}
};
this.set = this.setFn;
}
$get() {
return Object.create(this, {
init: {
value: (elm) => {
if (!window.intlTelInputUtils) {
console.log('intlTelInputUtils is not defined. Formatting and validation will not work.');
}
elm.intlTelInput(props);
}
},
});
}
}
Below is my app.js file:
angular.module('sample-app', [ngRoute])
.config(routing)
.provider('ngIntlTelInputPr', NgIntlTelInputProvider)
.directive('ngIntlTelInput', () => new NgIntlTelInput());
While trying to inject the provider into the directive, it's showing up as undefined
. Here's my directive implementation:
export default class NgIntlTelInput {
constructor(ngIntlTelInputPr, $log, $window, $parse) {
this.restrict = 'A';
this.require = 'ngModel'
this.ngIntlTelInputPr = ngIntlTelInputPr;
console.log('Provider:', ngIntlTelInputPr)
}
}
NgIntlTelInput.$inject = ['ngIntlTelInput', '$log', '$window', '$parse'];