Recently, I configured a Provider that fetches a language JSON file from a web server and delivers it to Angular within the config() method. Here is the provider setup:
.provider('language', function () {
var languageWsURL
, languageCode
, languageAppName;
return {
'setLanguageWsURL' : function (url) {
languageWsURL = url;
},
'setLanguageAppName' : function (name) {
languageAppName = name;
},
'setLanguageCode' : function (code) {
languageCode = code;
},
'$get': ['$rootScope', '$window', '$http', function ($rootScope, $window, $http) {
var loadLanguage = function () {
if (languageWsURL && languageCode && languageAppName) {
$http({
'method':'GET',
'url': languageWsURL,
'params': {
'application':languageAppName,
'langCode':languageCode
}
}).success(function (data) {
if (data.data && data.data.length > 0) {
$rootScope.lang = data.data;
}
}).error(function (err) {
$window.console.log('Error while retrieving app lang - languageProvider : ' + err);
});
} else {
$window.console.error('Missing params to load language in languageProvider');
}
};
return {
'loadLanguage':loadLanguage
};
}]
};
});
In addition, I added a configuration function in index.js:
.config(['languageProvider', function (languageProvider) {
languageProvider.setLanguageWsURL('http://localhost:3000');
languageProvider.setLanguageAppName('antani');
languageProvider.setLanguageCode('en');
languageProvider.loadLanguage(); //error here
}]);
However, there seems to be an issue as the languageProvider.loadLanguage() call results in a complex error message in the console:
http://errors.angularjs.org/1.2.23/$injector/modulerr?p0=app&p1=TypeError%3A%20undefined%20is%20not%20a%20function%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8000%2Fassets%2Fjs%2Findex.js%3A15%3A21%0A%20%20%2
Any ideas on how to resolve this issue?