Angular assign data from a POST request

0

Good people I have the following code

app.controller('lista', function($http){
        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
        //this.feriados = <?php echo json_encode($feriados->feriados); ?>;

        this.feriados = {};

        $http({
            method: 'POST',
            url: '../controllers/feriados.php',
            data: "op=listaTodos"
        }).then(function (respondse){
            this.feriados = response.data;
            console.log(this.feriados);
        },function (error){

        });


       });

My problem is that in printing to the console the "holidays" appear, but if I do <div ng-controller="lista as l"> {{ l.feriados }}</div> I see that the variable retains the {} value.

    
asked by anonymous 09.05.2017 / 12:47

1 answer

0

I discovered the error:)

You're assigning the variable this , judging your reach .

Just add it inside the controller

var controller = this;

And then assign the response to this variable

controller.feriados = resposta;
    
09.05.2017 / 13:04