personManagerInstance.getString("firstname",'common','en') I am currently passing a direct string in the UI which is affecting it. What I actually need is to read the data from a JSON file and return it as a string.
personManagerInstance.getString("firstname",'common','en') method needs to read the data from a JSON file and return it as a string or object?
personManagerInstance.getString("lastname",'registration','en') This method reads the JSON from a different location based on parameters and returns it as a string.
var PersonManager = function ()
{
return {
$get: function ($http, person)
{
var mainInfo = $http({
method: "get",
//"js/resources-locale_en_es.json"
url: "js/resources-locale_en_es.json"
}).success(function (data) {
return data.title;
});
return {
getPersonFirstName: function ()
{
return "as";
},
getPersonLastName: function ()
{
return person.lastname;
},
getString: function (labelid, moduleName, language)
{
//Here am getting the value id, moduleName, language based on the vaule I need to change the url path
//(i.e) js/resources-locale_en_es.json, js/registration/resources-locale_en_es.json
var l = maininfo.success(function (data) {
person.firstName = data.title;
})
return person.firstname;
}
};
}
};
};
angular.module("mainModule", [])
.value("person", {
firstname: "",
lastname: ""
})
.provider("personManager", PersonManager)
.controller("mainController", function ($scope, person, personManager)
{
person.firstname = "John";
person.lastname = "Doe";
$scope.personInstance = person;
$scope.personManagerInstance = personManager;
});
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="mainModule">
<div ng-controller="mainController">
<strong>First name:</strong> {{personManagerInstance.getPersonFirstName()}}<br />
<strong>Last name:</strong> {{personManagerInstance.getPersonLastName()}}<br />
<strong>Full name:</strong> {{personManagerInstance.getString("firstname",'common','en')}} {{personManagerInstance.getString("lastname",'registration','en')}}<br />
<br />
<label>Set the first name: <input type="text" ng-model="personInstance.firstname"/></label><br />
<label>Set the last name: <input type="text" ng-model="personInstance.lastname"/></label>
</div>
</body>
</html>