3

The result page is empty and doesn't show any data

Js File contains :

var Movies = angular.module('Movies', []);
Movies.controller('MoviesController',['$scope', '$http', function      
($scope, $http) {
    $http.get('http://localhost:19290/CinemaAngularJs/JS/data.json')
    .success(function (data) {
      $scope.Movies = data.Movs;
    })
    .error(function (data) {
      alert("Error occur");
    });
}]);

Data.json File contains :

"Movs":[
{
  "name":"Mision Impossible",
  "img":"mi",
  "year":"2012",
  "short":"Mision Impossible 2012 Mision Impossible 2012Mision Impossible  
2012 Mision Impossible 2012",
  "description":"Mision Impossible 2012 Mision Impossible 2012Mision 
},
{
.............
}]

HTML File contains :

<html xmlns="http://www.w3.org/1999/xhtml" ng-app="Movies">
<head runat="server">
  <title></title>    
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.1/angular2.min.js"></script>
  <script src="angular.min.js"></script>
  <script src="JS/controller.js"></script>
</head>
<body>
  <form id="form1" runat="server">
    <div ng-controller="MoviesController">
      <ul class="large-block-grid-4 small-block-grid-2">
        <li ng-repeat="mov in Movies">
           <h2>name : {{mov.name}}</h2>
           <img ng-src="Img/{{mov.img}}.jpg" alt="Image Here" />
           <h3>year : {{mov.year}}</h3>
           <h3>year : {{mov.short}}</h3>
           <h3>year : {{mov.description}}</h3>
         </li>
      </ul>
    </div>
  </form>
</body>
</html>

What are Errors in code ? What I can should do to run code ?

2
  • 1
    Take a little pride in your question. Clean it up and we will help. Commented Feb 11, 2016 at 12:10
  • There is nothing wrong with the code (but i did run it in angular 1.4 vs 2.0 ) jsfiddle.net/ncapito/zsj835mc/2 I would suggest you take a look at your data and make sure its coming back correctly. Commented Feb 11, 2016 at 12:20

3 Answers 3

2

Please console.log(data) and check it. Is valid JSON object or JSON string? I think we need:

$http.get('http://localhost:19290/CinemaAngularJs/JS/data.json').success(function (data) {
    var temp =JSON.parse(data);
    $scope.Movies = temp.Movs;
    })
    .error(function (data) {
        alert("Error occur");
    });
Sign up to request clarification or add additional context in comments.

1 Comment

Also I haven't any result "empty page"
1

Your JSON is invalid, try something like:

{
	"Movs": [{
		"name": "Mision Impossible",
		"img": "mi",
		"year": "2012",
		"short": "Mision Impossible 2012 Mision Impossible 2012Mision Impossible 2012 Mision Impossible 2012",
		"description": "Mision Impossible 2012 Mision Impossible 2012Mision"
	}]
}

I have validate this code, it's ok.

Your angular code is correct but you could validate if the result contains any data and show a warning. Just a suggestion.

Comments

1

Run the developer tools by pressing F12 in your browser. Are you shown any error messages in the console window?

This will show you any errors in the syntax...but not your logic!

UPDATE: Your JSON is invalid. Try pasting it in to www.jsoneditoronline.org to see for yourself.

Can you change your JSON to:

{
"Movs": [{
    "name": "Mision Impossible",
    "img": "mi",
    "year": "2012",
    "short": "Mision Impossible 2012 Mision Impossible 2012Mision Impossible 2012 Mision Impossible 2012",
    "description": "Mision Impossible 2012 Mision Impossible 2012Mision"
}]
}

4 Comments

When Run the code and press F12 in browser console window is empty "have no errors"
Then the code doesn't have any errors. What about the file you are loading? Do you know if the app is reading it?
the page can't read the json file I want to know why? and I want to view json file in html page .
The JSON is invalid. I will update my answer to show you.

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.