angular

by kiokotzu

HTML

<script src="angular-1.0.1.js"></script>
<div ng-app>
  <section ng-controller="TodoCtrl">
    
		<div>{{produc}}</div>
  </section>
</div>

CSS

div {
  word-wrap: break-word;
}

JavaScript

var productoT = [];

var dato2 = {
		code: '1',
		result: '',
		producto: {
			activo: 'si',
			nombre: 'Producto 1',
			genero: 'femenino',
			cantidad: 10,
			precio: 2500,
			vencimiento: '2016-11-15 00:00:00'
		}
	};

var myApp = angular.module('myApp',[])

//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

function TodoCtrl ($scope, $timeout, $http){
	var dato1 = {
      actionType: 'get',
      iduser: 1
    }
	$scope.name = 'guia';
	$http({
    method: 'POST',
    url: 'https://grancomunicaciones.com/clientes/gangastik/app/services/ProductosService.php',
    data:dato1,
    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
  }).success(resulProductos($scope, $timeout, $http));
	console.log(productoT);
	$scope.produc = productoT;
}

function resulProductos($scope, $timeout, $http){
	return function (res) {
    var dato, prod;
		$scope.Pdato1 = res;
    if (res.code == '0') {
      prod = res.productos;
      prod.forEach(function (dat1) {
        //dato = new ObjProducto(dat1.id, dat1.tipo,findGeneral(dat1.id, 'tipo', dat1))
        buscarInfoProducto($scope, $http, dat1.id, dat1.tipo)
        //console.log(dato);
      });
    }
    else{
      alert('error')
    }
  }
}

function buscarInfoProducto ($scope, $http, id, tipo) {
  var datoProducto;
  console.log(id + '-' + tipo);
  $http({
    method: 'POST',
    url: 'https://grancomunicaciones.com/clientes/gangastik/app/services/ProductosService.php',
    data: {
      actionType: 'getInfo',
      idproducto: id,
      tipo: tipo
    },
		headers: {'Content-Type': 'application/x-www-form-urlencoded'}
  }).success(function (res) {
      if (res.code == '0') {
				$scope.Pdato2 = res;
        datoProducto = new ObjProducto(id, tipo, res.producto);
        productoT.push(datoProducto);
      }
      else if (res.code == '54') {
        alert('error')
      }
      else{
        console.log(res)
      }
    });
}

function ObjProducto (id, tipo, dato) {
...