Related
I'm trying to populate number of tables dynamically by the input I get via JSON in angularJS.
I am perplexed on what to use and how to use since I am a learner in angular.
Would be helpful if anybody could help.
I have this JSON obtained in my script.
{
"took": 167,
"timed_out": false,
"_shards": {
"total": 10,
"successful": 10,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 22.126987,
"hits": [
{
"_type": "data",
"_id": "3423",
"_score": 22.126987,
"_source": {
"mdmId": "45234",
"fullName": "rick j cruz",
"firstName": "rick",
"middleName": "j",
"lastName": "cruz",
"gender": "MALE",
"employeeInd": "N",
"phoneList": [],
"partyAdresses": [
{
"addressType": "home",
"address1": "xxx",
"address2": "yyy",
"city": "SAN JOSE",
"state": "CA",
"zipCode": "zzz"
},
{
"addressType": "mailing",
"address1": "xxx",
"address2": "yyy",
"city": "SAN JOSE",
"state": "CA",
"zipCode": "zzz"
}
],
"policyList": [
{
"agencyCode": "50000",
"agentid": "500",
"sourceSystem": "unit",
"policyNumber": "123",
"policyNumberRaw": "123",
"policyStatus": "CANCELLED",
"roleList": [
{
"roleType": "INSURED",
"roleStatus": "ACTIVE",
},
{
"roleType": "LISTED DRIVER",
"roleStatus": "ACTIVE",
}
]
}
]
}
},
{
"_type": "data",
"_id": "3423",
"_score": 22.126987,
"_source": {
"mdmId": "45234",
"fullName": "rick j cruz",
"firstName": "rick",
"middleName": "j",
"lastName": "cruz",
"gender": "MALE",
"employeeInd": "N",
"phoneList": [],
"partyAdresses": [
{
"addressType": "home",
"address1": "xxx",
"address2": "yyy",
"city": "SAN JOSE",
"state": "CA",
"zipCode": "zzz"
},
{
"addressType": "mailing",
"address1": "xxx",
"address2": "yyy",
"city": "SAN JOSE",
"state": "CA",
"zipCode": "zzz"
}
],
"policyList": [
{
"agencyCode": "50000",
"agentid": "500",
"sourceSystem": "unit",
"policyNumber": "123",
"policyNumberRaw": "123",
"policyStatus": "CANCELLED",
"roleList": [
{
"roleType": "INSURED",
"roleStatus": "ACTIVE",
},
{
"roleType": "LISTED DRIVER",
"roleStatus": "ACTIVE",
}
]
}
]
}
}
]
}
}
I now need to populate two different tables based on the total value, mentioned in the JSON.
In case if the JSON returns 3, 3 tables needs to be populated. Eg: Below format.
Can someone help me with a fiddle or something?
Since you want to render out n "hits" with (I guess) som intensive styling and a lot more info than described, I think you should place it in a small directive :
angular.module('myApp').directive('hitTable', function() {
return {
scope: {
hit: '='
},
templateUrl: 'views/hitTable.html'
}
});
hitTable.html could look like this (based on sample boxes in the question, add more of the info you want rendered and you must do the styling yourself) :
<div>
<div> {{ hit._source.mdmId }}</div> <!-- sample box #1 -->
<div> {{ hit._source.firstName }}, {{ hit._source.lastName }}</div> <!-- sample box #2 -->
<div>
<span ng-repeat="address in hit._source.partyAdresses"> <!-- n of sample box #3 -->
{{ address.address1 }}
{{ address.city }}
{{ address.state }}
</span>
</div>
<div>
Once registered in your app and assuming $scope.data hold the sample JSON above you can do
<div ng-repeat="hit in data.hits.hits">
<hit-table hit="hit"></hit-table>
</div>
In my opinion this is the real power of AngularJS (and its like). With very little effort you can have a rather complex page structure. What you need now is to style each "hit", i.e the content of hitTable.html.
NB: I intentionally forget all about "total" here. The important is the content you want to render out, i.e whats within the JSON.
I am trying to get the values as a drop down or select field which were with in the comments array.
I am trying for comments array of object commentText values in the drop down, how can i do this in the ng-option ?. My Plunker
For Example:
I have did the drop down ng-option for first without array value like ng-options="item.title for item in questions".
What I am exactly looking for comments array of object values [commentText": "7A"] in the drop down how can i do that.
I tried ng-options="item for item.comments.commentText in questions" it's not working for me. How to fix it?
My Data:
$scope.questions = [
{
"_id": "59df6c37b6748bc809050699",
"user": {
"_id": "59df6a76b6748bc809050697",
"profileImageURL": "modules/users/client/img/profile/default.png"
},
"__v": 1,
"comments": [
{
"created": 1507897712831,
"email": "ms#e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "7A"
}
],
"questionid": "",
"created": "2017-10-12T13:20:55.383Z"
}
]
My Html:
<label>1. Without array value</label>
<select ng-model="class" ng-options="item.title for item in questions">
</select>
</div>
<div style="margin-top: 11px;">
<label>2. With comments array value</label>
<select style="margin-left: 20px;" ng-model="class" ng-options="item for item.comments.commentText in questions">
</select>
</div>
Looks for second solution is :-
I just want if we select question , comments select filter only this question's comments...how to do this... thanks
var myApp = angular.module('exApp',[]);
myApp.controller('myctrl', function($scope){
$scope.questions = [
{
"_id": "59df6c37b6748bc809050699",
"user": {
"_id": "59df6a76b6748bc809050697",
"profileImageURL": "modules/users/client/img/profile/default.png"
},
"__v": 1,
"openeyers": [],
"openeyes": 0,
"upvoters": [],
"upvotes": 0,
"isLiked": false,
"users": [],
"comments": [
{
"created": 1507897712831,
"email": "ms#e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "7A"
},
{
"created": 1507897712831,
"email": "ms#e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "9A"
},
{
"created": 1507897712831,
"email": "ms#e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "10A"
}
],
"questionid": "",
"title": "Silver jublie",
"created": "2017-10-12T13:20:55.383Z"
},
{
"_id": "59df6c37b6748bc809050699",
"user": {
"_id": "59df6a76b6748bc809050697",
"displayName": "Maniselvam selvam",
"dob": "1991-05-10T07:00:00.000Z",
"profileImageURL": "modules/users/client/img/profile/default.png"
},
"__v": 1,
"openeyers": [],
"users": [],
"comments": [
{
"created": 1507897712831,
"email": "ms#e21designs.com",
"name": "Maniselvam selvam",
"link": "https://drive.google.com/drive/u/0/folders/0B5c-p1bvkfS9REJHMGhMY1BTV1k",
"commentText": "8A"
}
],
"questionid": "",
"title": "Public School",
"created": "2017-10-12T13:20:55.383Z"
}
];
$scope.editClass = function(section){
$scope.sectionwithObject = section;
$scope.sectionOnly=section.commentText;
$scope.newLink = section.link;
}
});
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular.min.js"></script>
</head>
<body ng-app="exApp" ng-controller="myctrl">
<div>
<div>
<label>1. Without array value</label>
<select ng-model="ques" ng-options="item.title for item in questions">
</select>
</div>
<div style="margin-top: 11px;">
<label>2. With comments array value</label>
<select style="margin-left: 20px;" ng-model="commen" ng-options="item as item.commentText for item in ::ques.comments" ng-change="editClass(commen)">
</select>{{commen}}
<br><br>
<div>
<input type="text" ng-model="sectionwithObject.commentText"/><br><br>
<input type="text" ng-model="sectionOnly"/>
</div><br>
<div>
<lable> Link</lable>
<input type="text" ng-model="sectionwithObject.link" /><br><br>
<input type="text" ng-model="newLink" />
</div>
</div>
</div>
</body>
</html>
Just change your second select something like:-
<select style="margin-left: 20px;" ng-model="class" ng-options="item.commentText for item in question.comments">
</select>
Working demo
How can i filter category values in list, when clicking on a radio button?
My Plunker
Actually I want to filter category values in list of questions.
we have user data's and question data's in plunker.
user has two categories like "categories": ["Religion & Culture","Social Psychology"],.
question has various of categoryin list.
I am exactly looking to filter user categories values only, in that question category lists.
For Example :- in plunker we have displayed category values using of ng-repeat. the user categories array values are displayed using of two radio buttons, 1.Religion & Culture 2. Social Psychology. if we click the first radio button of Religion & Culture it's should filter only the Religion & Culture in question lists and if we click the second radio button of Social Psychology it's should filter only the religon & Culture values in question lists. .
My HTML radio button:-
<ul>
<li ng-repeat="mani in users" ><input type="radio" name="myquestion" data-ng-model="myquestion" ng-value="{{mani.categories[0]}}" id="{{mani.categories[0]}}"><label for="{{mani.categories[0]}" >{{mani.categories[0]}}</label>
</li>
<li ng-repeat="mani in users" ><input type="radio" name="myquestion" data-ng-model="myquestion" ng-value="{{mani.categories[1]}}" id="{{mani.categories[1]}}"><label for="{{mani.categories[1]}" >{{mani.categories[1]}}</label>
</li>
</ul>
My HTML Filter:-
ng-repeat="question in questions | filter:myquestion"
My Html Data:-
<div ng-repeat="question in questions | filter:myquestion">
<small>
<span >{{$index + 1}}.</span>
<span >{{question.category}}</span>
</small>
</div>
My Controller User Data:-
$scope.users=[
{
"_id": "58e73c5c9e2f3f1421e241be",
"displayName": "sarawana kumar",
"provider": "local",
"location": "chennai",
"username": "sarawana",
"dob": "1991-10-04T18:30:00.000Z",
"phone": 7299345250,
"religion": "hindu",
"__v": 0,
"created": "2017-04-07T07:14:36.773Z",
"roles": [
"user"
],
"category": [],
"profileImageURL": "modules/users/client/img/profile/default.png",
"email": "sarawana#gmail.com",
"categories": [
"Religion & Culture",
"Social Psychology"
],
"lastName": "kumar",
"firstName": "sarawana"
}]
My Question Data:-
$scope.questions = [
{
"_id": "5863d3aaacaeddc00663bc07",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"dob": "2016-12-22T18:30:00.000Z",
"location": "chennai",
"religion": "hindu",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag": [],
"emotion": "Confused",
"category": "Religion & Culture",
"content": "mani",
"title": "Who Is the best Player?",
"created": "2016-12-28T15:00:58.777Z"
},
{
"_id": "5863d3aaacaeddc00663bc07",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"dob": "2016-12-22T18:30:00.000Z",
"location": "chennai",
"religion": "hindu",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag": [],
"emotion": "Confused",
"category": "Moral Ethics",
"content": "mani",
"title": "Who Is the best Player?",
"created": "2016-12-28T15:00:58.777Z"
},
{
"_id": "5863d3aaacaeddc00663bc07",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"dob": "2016-12-22T18:30:00.000Z",
"location": "chennai",
"religion": "hindu",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag": [],
"emotion": "Confused",
"category": "Social Psychology",
"content": "mani",
"title": "Who Is the best Player?",
"created": "2016-12-28T15:00:58.777Z"
},
{
"_id": "5863d3aaacaeddc00663bc07",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"dob": "2016-12-22T18:30:00.000Z",
"location": "chennai",
"religion": "hindu",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag": [],
"emotion": "Confused",
"category": "Environment & Health",
"content": "mani",
"title": "Who Is the best Player?",
"created": "2016-12-28T15:00:58.777Z"
},
{
"_id": "5863d3aaacaeddc00663bc07",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"dob": "2016-12-22T18:30:00.000Z",
"location": "chennai",
"religion": "hindu",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag": [],
"emotion": "Confused",
"category": "Religion & Culture",
"content": "mani",
"title": "Who Is the best Player?",
"created": "2016-12-28T15:00:58.777Z"
},
{
"_id": "5863d3aaacaeddc00663bc07",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"dob": "2016-12-22T18:30:00.000Z",
"location": "chennai",
"religion": "hindu",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag": [],
"emotion": "Confused",
"category": "Religion & Culture",
"content": "mani",
"title": "Who Is the best Player?",
"created": "2016-12-28T15:00:58.777Z"
},
{
"_id": "5863d3aaacaeddc00663bc07",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"dob": "2016-12-22T18:30:00.000Z",
"location": "chennai",
"religion": "hindu",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/profile/uploads/ac4fbab396c2f725ed5211524f171136"
},
"friend_tag": [],
"emotion": "Confused",
"category": "Social Psychology",
"content": "mani",
"title": "Who Is the best Player?",
"created": "2016-12-28T15:00:58.777Z"
}
]
Plunker for reference.
We don't know where i did a mistake so please look my plunker for reference and help me.. please update the plunker as well to know the exact solution...thanks.
i have created similar answer please check this plunker http://plnkr.co/edit/1Zzc6nRylgETOvQp3SI2?p=preview i am exactly looking for the same answer in this plunker filtering the values but i want to filter user categories array values.....
Please refer this and we will improve code and filtering
code
I wrote this method
$scope.changed = function (category) {
$scope.result = [];
angular.forEach($scope.questions, function(question) {
if(question.category === category) {
$scope.result.push(question);
}
});
};
I think the problem is just because you used {{...}} inside of an ngValue, which is not necessary.
And also you tried to use myquestion to filtre your datas. But you setted this value for every items in ngRepeat in the same variable. So you need to use an array or different variable depending on the ngRepeat item (or don't use ngRepeat if you have only 1 user) like this :
<div class="col-md-3" ng-init="myquestion = []">
<ul ng-repeat="mani in users">
<li>
<input type="radio" name="myquestion" data-ng-model="myquestion[$index]" ng-value="mani.categories[0]" id="{{mani.categories[0]}}">
<label for="{{mani.categories[0]}" >{{mani.categories[0]}}</label>
</li>
<li>
<input type="radio" name="myquestion" data-ng-model="myquestion[$index]" ng-value="mani.categories[1]" id="{{mani.categories[1]}}">
<label for="{{mani.categories[1]}" >{{mani.categories[1]}}</label>
</li>
</ul>
Look a this plunker
If you want to filter your list dynamically then better solution would be filter data directly instead of using angular ng-repeat filter.
So all you need to do is just add $scope.filteredUsers that will be the result of filtering $scope.users each time the user chagnes radio button state.
You can accomplish it bu using ng-change directive along with your radio button.
Hovewer, if you still want to filter your data using directive, you need to write your own filter. Consider looking at this question and relative solutions.
angular.module('myApp', []).controller('candidateCtrl', function($scope) {
$scope.candidates = [
{name:'Goutam',role:'Engineer',country:'Norway'},
{name:'Carl',role:'Engineer',country:'Sweden'},
{name:'Margareth',role:'Doctor',country:'England'},
{name:'Hege',role:'Engineer',country:'Norway'},
{name:'Joe',role:'Engineer',country:'Denmark'},
{name:'Gustav',role:'Doctor',country:'Sweden'},
{name:'Birgit',role:'Teacher',country:'Denmark'},
{name:'Mary',role:'Engineer',country:'England'},
{name:'Kai',role:'Teacher',country:'Norway'}
];
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body ng-app="myApp">
<div class="container" ng-controller="candidateCtrl">
<h2>Bootstrap inline Radio Buttons</h2>
<div class="row">
<div class="col-lg-4">
<p>Angular JS Filter by Radio Button</p>
<form>
<label class="radio-inline">
<input type="radio" name="optradio" ng-model="searchText.role" value="Engineer">Engineer
</label>
<label class="radio-inline">
<input type="radio" name="optradio" ng-model="searchText.role" value="Doctor">Doctor
</label>
<label class="radio-inline">
<input type="radio" name="optradio" ng-model="searchText.role" value="Teacher">Teacher
</label>
</form>
</div>
</div>
<div class="row">
<div class="col-lg-4">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Profession</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="candidate in candidates | filter:searchText:strict">
<td>{{candidate.name}}</td>
<td>{{candidate.role}}</td>
<td>{{candidate.country}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
angular.module('myApp', []).controller('candidateCtrl', function($scope) {
$scope.candidates = [
{name:'Goutam',role:'Engineer',country:'India'},
{name:'Carl',role:'Engineer',country:'Sweden'},
{name:'Margareth',role:'Doctor',country:'England'},
{name:'Hege',role:'Engineer',country:'Norway'},
{name:'Joe',role:'Engineer',country:'Denmark'},
{name:'Rathin',role:'Doctor',country:'India'},
{name:'Birgit',role:'Teacher',country:'Denmark'},
{name:'Mary',role:'Engineer',country:'England'},
{name:'Kai',role:'Teacher',country:'Norway'}
];
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body ng-app="myApp">
<div class="container" ng-controller="candidateCtrl">
<h2>Bootstrap inline Radio Buttons</h2>
<div class="row">
<div class="col-lg-4">
<p>Angular JS Filter by Radio Button</p>
<form>
<label class="radio-inline">
<input type="radio" name="optradio" ng-model="searchText.role" value="Engineer">Engineer
</label>
<label class="radio-inline">
<input type="radio" name="optradio" ng-model="searchText.role" value="Doctor">Doctor
</label>
<label class="radio-inline">
<input type="radio" name="optradio" ng-model="searchText.role" value="Teacher">Teacher
</label>
</form>
</div>
</div>
<div class="row">
<div class="col-lg-4">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Profession</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="candidate in candidates | filter:searchText:strict">
<td>{{candidate.name}}</td>
<td>{{candidate.role}}</td>
<td>{{candidate.country}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
I am trying to list all the books title, picture and author in the home page. But I am seeing nothing in the home page. Really need someone to help out. I am still learning how to use data coming from JSON.
Please see my codepen http://codepen.io/ccrash/pen/rLAVXG
home.html
<ion-view view-title="Dashboard">
<ion-content class="padding">
<h2>Ionic GET Json Example</h2>
<ion-item ng-repeat="x in books">
<div> {{x.data.items.title}} </div>
<div> {{x.data.items.image[0]}} </div>
<div> {{x.data.items.author}} </div>
</ion-item>
</ion-content>
</ion-view>
App.js
.controller('HomeCtrl', function($http, $scope, $ionicSideMenuDelegate) {
$scope.books = [
{
"status": "OK",
"data": {
"category": "book",
"language": "en",
"items": [
{
"category": "book",
"language": "en",
"title": "book 1",
"image": [
"https://pbs.twimg.com/profile_images/739247958340698114/fVKY9fOv.jpg"
],
"author": "Mr X",
"snippeted": "This is the snippets",
"summary": "Summary1",
"pub_datetime": "2016-08-18 18:56:00",
"link": "/news/1",
"sid": 1,
"mod_datetime": "2016-08-18 19:05:55",
"freecontent": "yes"
},
{
"category": "book",
"language": "en",
"title": "book 2",
"image": [
"http://www.vodafone.co.nz/cms/images/credit-card.jpg"
],
"author": "Mr Y",
"snippeted": "Snippet 2",
"summary": "Summary 2",
"pub_datetime": "2016-08-18 18:53:00",
"link": "/news/352837",
"sid": 2,
"mod_datetime": "2016-08-18 19:07:59",
"freecontent": "yes"
},
{
"category": "book",
"language": "en",
"title": "book 3",
"image": [
"https://i.ytimg.com/vi/LNuFe2HV8Bs/maxresdefault.jpg"
],
"author": "Mr Z",
"snippeted": "Snippet 3",
"summary": "Summary 3",
"pub_datetime": "2016-08-18 18:51:00",
"link": "/book/352835",
"sid": 3,
"mod_datetime": "2016-08-18 18:55:32",
"freecontent": "yes"
}
],
"next_cursor": "75a",
"next_url": "/c/en/book/75a?alt=json",
"mod_datetime": "2016-08-18 19:26:36"
}
}
];
})
Maybe you should learn more about json.
You should use ng-repeat="x in books[0].data.items" to get each book of your book list, then you can get image title like this {{x.title}}
I was write the code for displaying country details, but i didnot get the complete details from the json, why is this happen, is there any wrong with the syntax? I got only country name and population from the output.
<!DOCTYPE HTML>
<html ng-app='myApp'>
<head>
<title>search using filters</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.js"></script>
<script src="//ajax.googleapis.com/
ajax/libs/angularjs/1.2.12/angular-route.js"> </script>
<link rel="stylesheet" href="bootstrap-3.2.0-dist/css/bootstrap.css" />
<script type="text/javascript">
var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(function($routeProvider)
{
$routeProvider.
when('/',{
templateUrl:'partial2.html',
controller:'MyCtrl'
}).
when('/:countryName',{
templateUrl:'partial1.html',
controller:'oCtrl'
}).
otherwise({
redirectTo:'/'
});
});
myApp.controller('MyCtrl',function($scope,$http) {
$http.get('/Zjs/data/countries.json').success(function(data){
$scope.countries=data;
});
});
myApp.controller('oCtrl',function($scope,$routeParams,$http)
{
$scope.name=$routeParams.countryName;
$http.get('/Zjs/data/countries.json').success(function(data){
$scope.country=data.filter(function(entry){
return entry.name===$scope.name;
})[0];
});
});
</script>
</head>
<body>
<div class="container" ng-view></div>
</body>
</html>
//partial1
<h1>{{country.name}}</h1>
<ul>
<li>Image:<img ng-src="{{country.Image}}" width="300" height="300"></img></li>
<li>Population:{{country.population | number }}</li>
<li>Capital: {{country.cap}}</li>
</ul>
//partial2
<ul>
<li ng-repeat="con in countries"><a href="#/{{con.name}}" >{{con.name}}</a></li>
<ul>
//countries.json
[
{"name":"india", "population":12345682700,
"cap":"New Delhi",
"Image":"http://www.dollsofindia.com/
images/products/nature-posters/village-scene-DH52_l.jpg"},
{"cap":"Tokyo","name":"japan", "population":1382700,
"Image":"file:///C:/Users/USER/Pictures/er/gettt/3.jpg"
},
{"name":"South korea", "population":13700,
"cap":"Seoul","Image":"C:\Users\USER\Pictures\er\gettt\6.jpg"},
{"name":"iran", "population":132700,
"cap":"Tehran","Image":"C:\Users\USER\Pictures\er\gettt\9.jpg"},
{"name":"russia", "population":1485682700,
"cap":"Moscow","Image":"C:\Users\USER\Pictures\er\gettt\11.jpg"}
]
You have got unescaped backslashes in your json file, I would start by eliminating those and see where that takes you, when I tried your code, resolving that worked for me at least.
[
{
"name": "india",
"population": 12345682700,
"cap": "New Delhi",
"Image": "http://www.dollsofindia.com/images/products/nature-posters/village-scene-DH52_l.jpg"
},
{
"cap": "Tokyo",
"name": "japan",
"population": 1382700,
"Image": "file:///C:/Users/USER/Pictures/er/gettt/3.jpg"
},
{
"name": "South korea",
"population": 13700,
"cap": "Seoul",
"Image": "file:///C:/Users/USER/Pictures/er/gettt/6.jpg"
},
{
"name": "iran",
"population": 132700,
"cap": "Tehran",
"Image": "file:///C:/Users/USER/Pictures/er/gettt/9.jpg"
},
{
"name": "russia",
"population": 1485682700,
"cap": "Moscow",
"Image": "file:///C:/Users/USER/Pictures/er/gettt/11.jpg"
}
]
your json was not a valid one.. so please use this
[
{
"name": "india",
"population": 12345682700,
"cap": "New Delhi",
"Image": "http://www.dollsofindia.com/images/products/nature-posters/village-scene-DH52_l.jpg"
},
{
"cap": "Tokyo",
"name": "japan",
"population": 1382700,
"Image": "file: ///C: /Users/USER/Pictures/er/gettt/3.jpg"
},
{
"name": "Southkorea",
"population": 13700,
"cap": "Seoul",
"Image": "file: ///C: /Users/USER/Pictures/er/gettt/6.jpg"
},
{
"name": "iran",
"population": 132700,
"cap": "Tehran",
"Image": "file: ///C: /Users/USER/Pictures/er/gettt/9.jpg"
},
{
"name": "russia",
"population": 1485682700,
"cap": "Moscow",
"Image": "file: ///C: /Users/USER/Pictures/er/gettt/11.jpg"
}
]
you can test your json data is valid or not by using http://jsonlint.com