1

Here is my HTML file and JS file I'm not getting any data's from the JSON file to the html file Below I have HTML files and JS files:

<!Doctype html>
   <html ng-app>
   <head>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
    <script type="text/javascript">
      alert("c");
function imagecontroller($http,$scope){
    alert("cd");
    $http.get('ytdata.json').success(function(ytdata) {
        alert("cdscdsc");
                $scope.data = ytdata;
    });
}  
   </script>
 <style type="text/css">
        li{list-style:none;float:left;padding:20px;}
     a{text-decoration:none;}
 </style>
</head>
          <body>
   <div ng-controller="imagecontroller">
     <ul> 
     <li ng-repeat="datum in data">
              <a>
             <img ng-src="{{datum.thumbUrl}}"/>
                    <br />Id : {{datum.id}} 
                        <br />Purchase : {{datum.Purchase}} 
        </a>
    </li>
</ul>
</div>
   </body>
   </html>

This is my json file:

[
        {
            "id":"mobile.jpg",
            "thumbUrl":"image url",
            "Purchase":20000
        },
        {
            "id":"pendrive.jpg",
            "thumbUrl":"image url",
            "Purchase":400
        },
        {
            "id":"laptop.jpg",
            "thumbUrl":"image url",
            "Purchase":3833
        }

]

Please get me the output for this program

Thanks in advance

1
  • 1
    YOu never tell it to run your function... Commented Aug 4, 2015 at 18:04

1 Answer 1

1

Here is a working plunker of what you are trying to do:

Controller

app.controller('MainCtrl', function($scope, $http) {
  $scope.data = null;
  $http.get("data.json").success(function (data) {
    $scope.data = data;
  });
});

View

<body ng-controller="MainCtrl">
  <ul>
    <li ng-repeat="datum in data">
      <a>
        <img ng-src="{{datum.thumbUrl}}" />
        <br />Id : {{datum.id}}
        <br />Purchase : {{datum.Purchase}}
      </a>
    </li>
  </ul>
</body>
Sign up to request clarification or add additional context in comments.

3 Comments

iam having same code in my localhost but it's not working
No, you don't. You are not setting up your angular controller correctly. Please review the plunker I posted above for the proper way to declare angular modules.
actually my controller name is "Imagecontroller" I applied it in my html file and my js file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.