How to show data obtained from an object in angularjs?

0

I just made a query to my database which I return object

These store them in localstorage

localStorage.setItem("Tickets", JSON.stringify(response));

and in another function I call them like this:

var headshot = localStorage.getItem("Tickets");

It happens that I have a variable repo:

      var repos = [
    {
      'rut'      :  '...here..',
      'numero'       : '...here...',

    }

and I want to fill it with the data obtained and then display it in a search engine with ng-repeat ...

How can I do it?

I'm getting tangled up, Here I have the html code since I'm using Angular-material:

implement the second example:

link

thanks to those who are helping me!

    
asked by Hernan Humaña 11.10.2016 в 22:37
source

5 answers

0

As above, I also advise you not to use JSON.stringify

It is not necessary that you create a repos variable. To search within your ng-repeat list you can use "angle" filter, it's very simple. I leave the code

$scope.tickets = localStorage.getItem('Tickets');

In the html

<input type="text" placeholder="ingrese rut" ng-model="buscar">
<div ng-repeat="ticket in tickets | filter : buscar">
     {{ticket.rut}}
</div>

Codepen

    
answered by 11.10.2016 / 22:52
source
1

Do you need to save in LS and then get from LS every time you make a backend call? It would be convenient to use the function of success in the chain of promises of the service / factory first fill the variable with the data and then save in LocalStorage (I recommend ngStorage). Then you assign that variable to your corresponding $ scope to display the data in the ngRepeat. EYE! That the "search engine" (filter) of ngRepeat is very inefficient, try other alternatives such as ngTable. Greetings.

    
answered by 11.10.2016 в 22:48
1

As Pablo Alejandro says, you have to do JSON.parse , or in angular% angular.fromJson() , assign it to your variable and there if you pass it to your variable, but EYE if you use md-autocomplete (I suppose you are using it) you must put md-no-cache="true" so you can load changes in case the list is dynamic.

md-autocomplete uses a md-virtual-repeat which greatly improves the printing of many rows. (Use angular-material in several projects)

    
answered by 11.10.2016 в 23:06
0

the JSON.stringify(response) is converting the json object obtained to a string, to read it with ng-repeat you have to pass it back to json object, you can convert it with json_response_object = JSON.parse(string_response); and then the characteristic ng-repeat

<div ng-repeat="obj in json_response_object">
  <span>{{obj.numero}}</span>
  ....
</div>
    
answered by 11.10.2016 в 22:48
0

You can directly use the response data:

<div ng-controller="Controller">
  <ul>
    <li ng-repeat="cosa in datos">
      Rut: {{cosa.rut}} numero{{cosa.numero}}
    </li>
  </ul>
</div>

link

    
answered by 11.10.2016 в 22:52