How to load json file into Angularjs for ng-repeat

前端 未结 3 1422
春和景丽
春和景丽 2021-01-16 06:03

I have a simple json file with a list of artist names, like

[\"Vincent van Gogh\", \"Leonardo da Vinci\", \"Pablo Picasso\"]

I can\'t figur

相关标签:
3条回答
  • 2021-01-16 06:41

    you can try this:

     $http.get("/home/user/artist_names.json")
        .success(function(response) {$scope.artists = response;});
    
    0 讨论(0)
  • 2021-01-16 06:45

    I ran into this issue with a node server hosted in Azure and the fix was to ensure the mime type for JSON files was set properly. I was hosting in azure so that meant ensuring a web.config existed with the right settings, but I'm not sure what's required with Django. Without the proper mime type the server would report a 404 like you mentioned.

    0 讨论(0)
  • 2021-01-16 06:47

    Example link at the bottom for ng-repeat

    artApp.controller('TodoCtrl', function($scope, $http) {
    $http.get('/home/user/artist_names.json')
           .then(function(result){
              $scope.artists = result.data;                
            });
    });
    

    In html

      <ul>
        <li ng-repeat="artist in artists">
          {{artist.name}}
        </li>
      </ul>
    

    IN YOUR JSON

    [{ "name":"Vincent van Gogh"},
     { "name":"Leonardo da Vinci"},
     { "name":"Pablo Picasso"}]
    

    http://plnkr.co/edit/Wuc6M7?p=preview

    From jaime

    I ran into this issue with a node server hosted in Azure and the fix was to ensure the mime type for JSON files was set properly. I was hosting in azure so that meant ensuring a web.config existed with the right settings, but I'm not sure what's required with Django. Without the proper mime type the server would report a 404 like you mentioned.

    From Sam Storie

    0 讨论(0)
提交回复
热议问题