How do I modify the values that php brings in json format from angular

3

<!DOCTYPE html>
<html lang="es" ng-app="practica">
<head>
	<meta charset="UTF-8">
	<script type="text/javascript" src="angular.min.js"></script>
	<title>Document</title>
</head>
<body>
		<input type="text" ng-model="buscar" placeholder="Buscar">
<div ng-controller="ctrldatos">
<table>
	<tr>
		<th>Sub Categoria Codigo</th>
		<th>Sub Categoria Nombre</th>
		<th>Sub Categoria</th>
	</tr>
	<tr ng-repeat="x in names | filter:buscar ">
		<td>{{x.subcat_cod}}</td>
		<td>{{x.subcat_nom}}</td>
		<td>{{x.cat_cod}}</td>
	</tr>
</table>

</div>
</body>
<script type="text/javascript">
 angular.module("practica",[])
 	.controller("ctrldatos",function($scope,$http){
		$http.get("get.php")
		.success(function (response)
		{
			$scope.names = response;
		});
	});
</script>
</html>


Como puedo modificar los valores que trae php en formato json usando angular:
<script type="text/javascript">
 angular.module("practica",[])
    .controller("ctrldatos",function($scope,$http){
        $http.get("get.php")
        .success(function (response)
        {
            $scope.names = response;
        });
    });
</script>

'

    
asked by Jhosep Dominguez 25.03.2016 в 21:04
source

1 answer

0

You could work the data that you get from the $http in a angular.forEach to iterate each value and apply the condition that change the value of each item.

In this example

.controller("ctrldatos",function($scope,$http){
    $http.get("get.php")
    .success(function (response)
    {
        angular.forEach(response, function(value, key){
            if(value.subcat_cod == "1")
                value.subcat_nom = "otrovalor";
        });

        $scope.names = response;
    });
});

imagine that if the subcategory had a value changing the name, of course it is just an example that you should adapt.

You could also help with libraries such as underscorejs

This has functions such as _.map() to be able to convert each item from one list to another different one.

    
answered by 25.03.2016 в 21:23