Use variable located in the angularjs driver in the html!

2

I have the following doubt I am receiving data as follows:

    var Getcola= JSON.stringify(response.data);

    localStorage.setItem("GetMycola", Getcola);

     var cola1= localStorage.getItem("GetMycola");

     var Mycola = JSON.parse(cola1);

As you can see, they are json and I keep them inside a variable and then use them like this:

Mycola.rut 

Returning: 18.334.655-5 (ex.)

The problem that this code is configured in the controller that makes the request and ask how variable use to show the result in the html? Greetings.

    
asked by Hernan Humaña 21.09.2016 в 20:58
source

1 answer

1

To show the result of the variables they must be in the $ scope of your controller. You must declare it in the controller like this:

$scope.Mycola = JSON.parse(cola1);

Then in the html you must write your variable between "{{}}". In this way:

<p>{{Mycola.rut}}</p>

Make sure that the html is controlled by your controller with the directive ng-controller.

<body ng-controller="myController">

</body>
    
answered by 14.10.2016 в 09:07