0

Estoy haciendo una peticion post con el siguiente codigo JS

$scope.makeCall= function ($http) {
  url: 'https://prueba-web.herokuapp.com/session';
 
  $http.post(url, {
    "username": "test",
    "password": "test123",
    "type": "V"
}).done(function(data, status, headers, config) {
    console.log("Se llamo a esta funcion");
      $scope.seguro=data;
  }).error(function(data, status, headers, config) {
      alert("Ha fallado la petición. Estado HTTP:"+status);
  });

Pero en la consola de chrome me dice Cannot read property 'post' of undefined. Ya he googleado bastante. Soy muy nueva usando angular. Si alguien me puede orientar se lo agradezco porfa. No se si es que me falta algo en el código que por ignorancia no coloqué.... Les dejo todo mi controlador para que vean que tengo y que me falta.. Gracias :)

var app = angular.module("app",[]);
app.controller('controlador',['$scope', '$http',function($scope,$http){

  $scope.login.username="";
  $scope.login.password="";
  $scope.login.tipo="";
  var login= this;


/****************PETICION GET************************/
	$scope.makeCall= function ($http) {
  url: 'https://prueba-web.herokuapp.com/session';
 
  $http.post(url, {
    "username": "test",
    "password": "test123",
    "type": "V"
}).done(function(data, status, headers, config) {
    console.log("Se llamo a esta funcion");
      $scope.seguro=data;
  }).error(function(data, status, headers, config) {
      alert("Ha fallado la petición. Estado HTTP:"+status);
  });


}] );

1 respuesta 1

0

Ya encontré el problema. Lo compartiré por si a alguien más le sucede. Entre tanto googlear vi que no debía pasarle $http como parametro a la funcion makeCall. Aparte de esto me surgieron dos errores mas con las funciones done, success, y error. Al googlear me di cuenta que estan deprecados asi que los cambie por Then y asi me funciona. El problema ahora es que los datos que envio en la peticion no estan llegando :S

1
  • Entonces esta es la solución a tu pregunta?
    – user128299
    el 13 oct. 2019 a las 22:16

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.