Skip to content Skip to sidebar Skip to footer

Import Json Data And Show It In Angular App

i started learning angular a week ago, and now im trying to construct a app by myself (because people say that is the best way to learn), im trying to do a thing that i didnt befor

Solution 1:

ng-repeat = "pokemon in pokedex.pokemons"

you are using ng-repeat on pokedex.pokemons you have to assign data to pokedex.pokemons from controller where you are getting data.

$http.get('https://pokedex-deluxor.rhcloud.com/getall').success(function(data){
 // assign data here
});

Solution 2:

you should assign the data returned from your http request to the scope object pokemons. since you used controller as syntax you should do

JS

(function(){

var app = angular.module('pokedex',[]);

app.controller('pokemonController',['$http',function($http){
    $http.get('https://pokedex-deluxor.rhcloud.com/getall').success(function(data){
    this.pokemons = data;
    });
}]);
});

HTML

<div class="row" ng-controller="PokemonController as pokedex">
<divclass="col-md-offset-1 col-md-6"ng-repeat = "pokemon in pokedex.pokemons"><p>Name: {{pokemon.Name}}</p></div>

Post a Comment for "Import Json Data And Show It In Angular App"