I am currently working on integrating the $translate.proposedLanguage() function into an AngularJS component to set up and configure the intl-tel-input plugin:
function customTel() {
return {
restrict: 'A', // restriction as Attr
require: 'ngModel', // requirement of ngModel from html
scope: {},
link: function($scope, $elem, $attrs, $ctrl) {
var ngModelCtrl = $ctrl; // access ngModel using $ctrl
var language = $translate.proposedLanguage() || $translate.use();
if (language === "es") {
language = "ES";
} else if (language === "en") {
language = "GB";
} else if (language === "pt-pt") {
language = "PT"
}
$elem.intlTelInput({
initialCountry: language,
preferredCountries: ["ES", "GB", "PT", "US"],
nationalMode: true,
utilsScript: "../../webclientes/bower_components/intl-tel-input/build/js/utils.js"
});
}
}
}
angular
.module('webclientesApp')
.directive('customTel', customTel);
The issue I am facing is that $language appears to be undefined, despite being injected in the controller:
(function() {
'use strict';
angular
.module('webclientesApp')
.controller('ContactaController', ContactaController);
ContactaController.$inject = ['$scope', 'Principal', 'ContactaServiceRest', '$state', '$translate'];
function ContactaController ($scope, Principal, ContactaServiceRest, $state, $translate) {
...
I have attempted injecting it into the link parameter or within the .directive
section below, but so far, nothing seems to work.
Is there a way to access $translate through the component? Appreciate any insights!