I have a problem with using the JSON data which is comming from a service. The backend is written in c# and the frontend in AngularJS.
I am not able to use the object as I want in the Angular controller.
So, here is my api restful service in C#
[Route("v1/environment")]
public IHttpActionResult GetEnvironment()
{
var env = new Environment(WebConfigurationManager.AppSettings["Env"]);
return this.Ok(env);
}
Then, here is my angular service:
module.factory('Environment', [
'$resource',
function ($resource) {
return $resource('/MorpheusApi/v1/environment', {}, {
getEnv: {method: 'GET', isArray: false}
});
}
]);
Then for testing purpose I created also this service:
module.factory('Env', [
'Environment',
function (Environment) {
return {
getEnv: function () {
var s = Environment.getEnv();
var e = angular.fromJson(s);
return e;
}
};
}
]);
Then I would use it in controller like this:
$scope.envLocal = Env.getEnv();
Then in the ui, with this
<p>Environment Local: {{envLocal}}</p>
<p>Environment Local Env: {{envLocal.Env}}</p>
I am getting the following output, which is fine I think :)
Environment Local: {"Env":"testText"}
Environment Local Env: testText
But when I now want to let's say provide just the testText from the controller to the ui, I would do something like this:
var result = Env.getEnv();
$scope.envLocal = result.Env;
But this is then not working.. I tried it also with angular.toJson.. angular.fromJson, but I am not getting anything then in the UI.. Why? How can I use the object properly in the controller, for example if I want to use it in an if or whatever..
Is this even possible?