Searching a JSON file in AngularJS - javascript

So I have the following service/factory setup that should query a JSON file:
myappServices.factory('Result', ['$resource',
function($resource){
return $resource('search.json', {}, {
query: { method:'GET', params: {}, isArray:true }
});
}]);
And then in my SearchCtrl I have:
myappControllers.controller('SearchCtrl', function($rootScope, $scope, $state, Result, $location) {
$scope.query = ($state.includes('search') ? $location.search()['q'] : '');
$scope.filterQuery = ($state.includes('search') ? $location.search()['q'] : '');
$scope.queryChanged = function () {
if($scope.query){
$state.go('search', {'q': $scope.query} );
$scope.results = Result.query();
} else {
$location.search('q', null);
}
$scope.filterQuery = $scope.query;
}
if($scope.query){
$scope.results = Result.query();
} else {
$location.search('q', null);
}
});
The search results page looks like:
<ul class="ng-hide" ng-show="results.length > 0">
<li ng-repeat="result in results">
{{result.name}}
<p>{{result.snippet}}</p>
</li>
</ul>
<p class="ng-hide" ng-show="results.length == 0">Nothing here!</p>
If I do a query like:
/search?=hello
Then ALL the results in the JSON file are returned REGARDLESS of what I have searched for (should only be showing results that match).
However if I don't do a query then no results are shown (correct behaviour).
Why is the query not being used against the JSON file to filter the results?
I did originally have the repeater as:
<li ng-repeat="result in results = ( results | filter:filterQuery )">
But that would be incorrect in this case, as it's would be saying show me the results but filter them using the filterQuery. But in reality there would never be any results if no query, hence removing this part of the repeater. As I don't want to filter a list but return a list filtered.
So it would seem I am missing something in my service to handle this.

Edited: Simplify your resource so it doesn't define query:
myappServices.factory('Result', ['$resource',
function($resource){
return $resource('search.json');
}]);
Try changing your controller to clear the results and only set them when a query has been made:
myappControllers.controller('SearchCtrl', function($rootScope, $scope, $state, Result, $location) {
$scope.query = ($state.includes('search') ? $location.search()['q'] : '');
$scope.filterQuery = ($state.includes('search') ? $location.search()['q'] : '');
$scope.results = [];
$scope.queryChanged = function () {
if($scope.query){
$state.go('search', {'q': $scope.query} );
} else {
$scope.results = Result.query({q:$scope.query});
}
$scope.filterQuery = $scope.query;
}
});

app.factory('querySvc', ['$q', '$resource', querySvc]);
function querySvc($q, $resource) {
var service = {
getSearch: getSearch
}
return service;
function getSearch(){
var deferred = $q.defer();
$resource('search.json').query( function(data){
deferred.resolve(data);
}, function(error){
// handle error
});
return deferred.promise;
}
Then you can call it that way:
querySvc.getSearch().then(function (data){
$scope.results = data;
}, function(error){
//handle error here
});
About your first note :
When you instantiate your controller, it executes everything inside it.
So, if you want to call this function when a user clicks somewhere, you can register a function into the scope :
$scope.querySearch = function(){
querySvc.getSearch().then(function (data){
$scope.results = data;
}, function(error){
//handle error here
});
}
And then, into your view, you will have to call it when an event is fired.
I don't remember the event you need, but I'll show you a way of doing it :
<span ng-click="querySearch()" />
This will trigger the function when you click on the span.

In the console, look in the Network tab to see if the request has an error and/or to see the contents of the response. If the response has a status code of 200 and the contents are correct, then check the response to see if the data is structured correctly for results.length (that it returns a list).

Related

Including AngularJS code in HTML generated in JS

I'm working with an old version of AngularJS (1.3). I've got a page that I want to conditionally show different things based on the value in the database. If the value in the database is changed via user interaction, I want to update what's shown automatically. Part of what I show, however, is HTML and in that HTML I need to include some AngularJS code.
If the value is True, I want to show this HTML:
Your value is True. To set it to False, <a ng-click="myToggleFunction('paramValueFalse')">click here</a>.
If the value is False, I want to show this HTML:
You haven't done the thing, to do the thing, <a ng-click="myDifferentFunction('someOtherParamValue')">click here</a>.
I've got it so close to working: the content that shows changes out depending on what the user's value is, and it updates appropriately, and it's even rendering the HTML correctly (using $sce)... But the ng-click isn't functioning. Can you include angular in HTML that's being injected via JS like that?
Full code:
HTML:
<span ng-bind-html="renderHtml(html_content)"></span>
Controller:
function MyCtrl ($scope, $http, $sce, Notification) {
$scope.username = context.targetUsername;
$scope.content_options = {
'yes' : 'Your value is True. To set it to False, <a ng-click="myToggleFunction(" + "'paramValueFalse'" + ')">click here</a>.',
'no' : 'You haven\'t done the thing, to do the thing, <a ng-click="myDifferentFunction(" + "'someOtherParamValue'" + ')">click here</a>.'
}
$http.get(
'/api/v1/user/' + $scope.username + '/?fields=myBooleanField' // django rest api call
).then(function(response) {
$scope.user = response.data;
if ($scope.user.myBooleanField) {
$scope.html_content = $scope.content_options['yes'];
} else {
$scope.html_content = $scope.content_options['no'];
}
});
});
$scope.myToggleFunction = function(paramValue) {
// toggle value in the db
if (accepted === 'true') {
var success = "You turned on the thing";
var content = "yes";
} else {
var success = "You turned off the thing";
var content = "no";
}
$http({
method: 'GET',
url: '/api/v1/user/' + $scope.username + '/my_boolean_field/?value=' + paramValue, // django rest api call
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function(response) {
$scope.html_content = $scope.content_options[content];
Notification.success(success);
}, function(response) {
Notification.error("There was an error.");
});
};
$scope.myDifferentFunction = function(someOtherParamValue) {
// do some other stuff
};
$scope.renderHtml = function(html_code) {
return $sce.trustAsHtml(html_code);
};
}
MyCtrl.$inject = ['$scope', '$http', '$sce', 'Notification'];
As Sagar said above, the reason this is happening is because the html code returned by renderHtml is not compiled by AngularJS. I tried a few different takes on creating a directive that recompiles angular. For example:
https://github.com/incuna/angular-bind-html-compile
Rendering directives within $sce.trustAsHtml
ng-click doesn't fire when added post load
However, none of these were working for me. I'm not sure why; the content just wasn't displaying but there were no JS errors.
I ended up finding this solution, and it worked for me: Angular: ng-bind-html filters out ng-click?
Essentially, the solution is use raw JS to directly call the Angular functions, rather than using the ng-click directive in the JS-generated HTML content.
Here's what it looks like:
Template:
<div id="angularHtml" ng-bind-html="html_content">
<script>
function callAngular(controllerFunction, functionParam) {
var scope = angular.element(document.getElementById('angularHtml')).scope();
scope.$apply(function() {
{# couldn't figure out how to reference the function from the variable value, so this is hacky #}
if (controllerFunction == "myToggleFunction") {
scope.myToggleFunction(functionParam);
} else if (controllerFunction == 'myDifferentFunction') {
scope.myDifferentFunction(functionParam);
}
});
}
</script>
Controller:
function MyCtrl ($scope, $http, $sce, Notification) {
$scope.username = context.targetUsername;
$scope.content_options = {
'yes' : 'Your value is True. To set it to False, <a onClick="callAngular(\'myToggleFunction\', \'false\')">click here</a>.',
'no' : 'You haven\'t done the thing, to do the thing, <a onClick="callAngular(\'myDifferentFunction\', \'someValue\')">click here</a>.'
}
$http.get(
'/api/v1/user/' + $scope.username + '/?fields=myBooleanField' // django rest api call
).then(function(response) {
$scope.user = response.data;
if ($scope.user.myBooleanField) {
$scope.html_content = $sce.trustAsHtml($scope.content_options['yes']);
} else {
$scope.html_content = $sce.trustAsHtml($scope.content_options['no']);
}
});
});
$scope.myToggleFunction = function(paramValue) {
// toggle value in the db
if (accepted === 'true') {
var success = "You turned on the thing";
var content = "yes";
} else {
var success = "You turned off the thing";
var content = "no";
}
$http({
method: 'GET',
url: '/api/v1/user/' + $scope.username + '/my_boolean_field/?value=' + paramValue, // django rest api call
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function(response) {
$scope.html_content = $sce.trustAsHtml($scope.content_options[content]);
Notification.success(success);
}, function(response) {
Notification.error("There was an error.");
});
};
$scope.myDifferentFunction = function(someOtherParamValue) {
// do some other stuff
};
}
MyCtrl.$inject = ['$scope', '$http', '$sce', 'Notification'];
You can use ngShow and ng-hide for show and hide HTML dynamic
<div ng-show="DBvalue">Your value is True. To set it to False, <a ng-click="myToggleFunction('paramValueFalse')">click here</a>.</div>
<div ng-hide="DBvalue">You haven't done the thing, to do the thing, <a ng-click="myDifferentFunction('someOtherParamValue')">click here</a>.</div>

prevent multiple upvote Angularjs

To begin sorry for my English.
I made some search about this problem, but nothing works for me.
My problem is simple :
I have an upvote system, where users can upvote (like Stackoverflow). But the problem is that users can upvote multiple times (and it's not very well ..).
I tried to make a button with ng-disabled, but if i do this, users can only vote one time for all the posts (I mean if they upvoted "Post A", they can't upvote "Post B").
Here is my controller function :
$scope.incrementUpvotes = function(post) {
posts.upvote(post);
};
Here is my factory function :
o.upvote = function(post){
return $http.put('/posts/' + post._id + '/upvote', null, {
headers: {Authorization: 'Bearer '+auth.getToken()}
}).success(function(data){
post.upvotes += 1;
});
};
And here the html :
<span class="glyphicon glyphicon-thumbs-up" ng-click="incrementUpvotes(post)"></span>
If someone could help me it would be great ! Thanks in advance !
Please try to use button or input instead of span. Because disabled does not work in a span.
<button id="{{ post._id + 'upvote' }}" class="glyphicon glyphicon-thumbs-up" ng-click="incrementUpvotes(post)"></button>
Then set disabled attribute of your upvote button true after the upvote action.
o.upvote = function(post){
return $http.put('/posts/' + post._id + '/upvote', null, {
headers: {Authorization: 'Bearer '+auth.getToken()}
}).success(function(data){
post.upvotes += 1;
angular.element(document.getElementById(post._id + 'upvote' ))[0].disabled = true;
});
};
This is more of an architectural question than it is javascript/angularjs question. There are many ways to do this. But the idea is to store in database and persist upvote information, otherwise users can just refresh the page and upvote again.
Most direct solution is: You have to store your vote information on the backend at the user level. When you query the user information, store a list of up-voted posts like this:
myDataService should look like this:
angular.module("app", []).service("myDataService", ["$http","$q","$rootScope", function myDataService($http, $q, $rootScope) {
var myDataService = this;
myDataService.getPostsUpvoted = function(userId) {
var defer = $q.defer();
//here you format your payload to deliver userId to the api backend
var payload = { userId: userId };
//your api backend 'getpostsupvoted' should accept a userId, then in return it should
//deliver a list of posts upvoted by that user
$http.post("/api/getpostsupvoted", payload).then(function (data, status, headers, config) {
//call success
defer.resolve(data);
}, function(data, status, headers, config) {
//an error occurred
defer.reject(data);
});
return defer.promise;
}
return myDataService;
})];
Then, this is how you'll use the service in your controller.
//inject scope and myDataservice into controller
angular.module("app", []).controller("MainCtrl", ["$scope", "myDataService", function($scope, myDataService) {
//create a new array to hold a list of upvotes
$scope.user.upVoted = [];
myDataService.getPostsUpvoted($scope.user.id).then(function(data) {
//set upvoted array to data
$scope.user.upVoted = data;
}, function(error) {
//blah an error occurred
});
})];
In your controller, provide a function to check if a post has already been upvoted.
$scope.IsUpvotedAlready = function(postId) {
if($scope.user.upVoted.indexOf(postId) > -1)
return true;
return false;
}
You'll also have to push the post._id to the upVoted array and keep it there.
$scope.incrementUpvotes = function(post) {
//check if it's already been upvoted, then do nothing
if($scope.user.upVotes.indexOf(post._id) > -1)
return;
posts.upvote(post);
$scope.user.upVoted.push(post._id);
};
Then, in your ng-repeat directive where you display the post, check if the list of upvotes contain the post._id.
<div ng-repeat="post in posts">
<div ng-if="IsUpvotedAlready(post._id)">
<!-- display something since already upvoted !-->
</div>
{{ post }}
</div>
In the template when you are iterating the posts, have a flag for each post which identifies if it has been upvoted or not.
In the upvote function mark that flag as true and use it in the ng-disabled directive like this :
ng-disabled={{post.isUpvoted}}

ng-repeat not showing table rows after loading

I am experiencing some problems with not showing any data with ng-repeat.
Flow is as follows
I call a sharedObjects service before requesting data from the server, in case the needed data is already loaded and available.
The loading part works, and shows up in the console. There is a timeout set for testing purposes, and the page stays on loading view until data is loaded. But the rows are not showing up the first time. After going to another page and back to the page in question, the data shows fine and is loaded from the sharedObjects service.
My code is as follows
// dataService aka sharedObjects
angular.module('app').factory('dataService', function(){
var List = undefined;
return {
getList: function () {
return List;
},
setList: function (list) {
List = list;
},
}
});
// controller
angular.module('appWebmenu').controller('appWebmenuController', ['$scope', 'dataService', 'webmenuService', function($scope, dataService, webmenuService){
$scope.listLoaded = false; // data is not loaded flag
$scope.listError = false; // no errors occured yet flag
// function to load and pass the data to the ng-repeat
$scope.getItemList = function(){
// trying for preloaded data
$scope.itemList = dataService.getList();
console.log($scope.itemList);
if($scope.itemList === undefined){
// data not previously loaded get from server (service)
$scope.itemList = webmenuService.getWebmenuList($scope.shop_id,$scope.token)
// after data loads promise returned
.then(
// on success
function(data){
// by adding the extra call to the dataService, it works. Brilliant
$scope.itemList = dataService.getList();
$scope.listLoaded = true; // set the data as loaded
return data;
},
// on failure
function(data){
$scope.listLoaded = false; // data still not loaded
$scope.listError = true; // an error has occured
alert(data.errorMessage);
});
}
else{
$scope.listLoaded = true; // data returned from preloaded dataService
}
return $scope.itemList;
};
// dataRetrieval which connects to the server
angular.module('appWebmenu').factory('webmenuService', ['$q','$http', 'dataService','$timeout', function($q, $http, dataService, $timeout){
return {
getWebmenuList: function (shop_id, token) {
var dfr = $q.defer(); // init promise
// set retrieval settings
var req = {
method: 'POST',
url: "../api/v1/Webmenu/menulist/all",
headers: {
'Content-Type': 'application/json'
},
data: {shop_id: '' + shop_id,token: '' + token }
};
// execute retrieval request
$http(req)
// when loaded
.then(
// on success
function(response){
dataService.setList(response.data); // setting the data to the dataService for reuse
$timeout(function(){
dfr.resolve(response.data);
},5000);
},
// on failure
function(response){
dfr.reject( false );
});
return dfr.promise;
}
};
}]);
// directive
angular.module('appWebmenu').directive('appWebmenuList', function() {
return {
//require: '^appWebmenu',
transclude: true,
templateUrl: 'external/appWebmenu/appWebmenuListTemplate.html',
controller: 'appWebmenuController',
scope: {
},
link: function(scope, el, attr, ctrl) {
}
}
});
// Template
<!-- to show while loading -->
<div ng-if="!listLoaded"> // corresponds with $scope.listLoaded in the controller
<i class="fa fa-spinner fa-spin fa-3x"></i>
</div>
<!--show when an error occures-->
<div ng-if="listError"> // corresponds with $scope.listError in the controller
{{ 'ERROR_LOADING' | translate }}
</div>
<!-- show when data is loaded and no errors occured-->
<div ng-if="listLoaded && !listError && itemList"> // check if list is loaded, no errors occured and if itemList is not empty or undefined
<table class="webmenu-table-main">
<thead>
<tr>
<th>{{'PAGE' | translate}}</th>
<th>{{'ACTIONS' | translate}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in itemList">
<script>console.log('menu name is {{ item.menu_name }}');</script>
<td>{{item.menu_name}}</td>
<td>
<i class="fa fa-search" title="{{ 'DETAILS' | translate }}" ng-click="details(item.menu_id)" ng-if="item.menu_is_editable != '0'"></i>
<i class="fa fa-pensil-square" title="{{ 'EDIT' | translate }}" ng-click="edit(item.menu_id)" ng-if="item.menu_is_editable != '0'"></i>
<i class="fa fa-trash-o" title="{{ 'DELETE' | translate }}" ng-click="remove(item.menu_id)" ng-if="item.menu_is_editable != '0'"></i>
<i class="fa fa-plus" title="{{ 'ADDMENU' | translate }}" ng-click="addNewMenuItem(item.menu_id)"></i>
<i class="fa fa-external-link-square" title="{{ 'OPENEDITOR' | translate }}" ng-click="openInEditor(item.menu_id)" ng-if="item.menu_is_editable != '0'"></i>
</td>
</tr>
</tbody>
</table>
</div>
Is there something I am missing? This works only the times after the first time when the data is preloaded.
webmenuService.getWebmenuList returns a promise. Not data. You need to set $scope.itemList inside your then function call.
if($scope.itemList === undefined){
// data not previously loaded get from server (service)
var qListPromise = webmenuService.getWebmenuList($scope.shop_id,$scope.token)
// after data loads promise returned
.then(
// on success
function(data){
$scope.listLoaded = true; // set the data as loaded
return data;
},
// on failure
function(data){
$scope.listLoaded = false; // data still not loaded
$scope.listError = true; // an error has occured
alert(data.errorMessage);
});
qListPromise.then( function(data) { $scope.itemList = data;
}).catch( function(error) { throw error; });

How to bind data in json to li using Angular js

am try to develop an application using angular js in which i take take data from database and populate li using that data
for that i write a WebMethod as fallow
[WebMethod]
public static string getname()
{
SqlHelper sql = new SqlHelper();
DataTable dt = sql.ExecuteSelectCommand("select cust_F_name,Cust_L_Name from customer");
Dictionary<string, object> dict = new Dictionary<string, object>();
object[] arr = new object[dt.Rows.Count];
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
arr[i] = dt.Rows[i].ItemArray;
}
dict.Add(dt.TableName, arr);
JavaScriptSerializer json = new JavaScriptSerializer();
return json.Serialize(dict);
}
which return data in json form
am use the fallowing js to bind
var DemoApp = angular.module('DemoApp', []);
DemoApp.factory('SimpleFactory', function () {
var factory = {};
var customer;
$.ajax({
type: "POST",
url: "Home.aspx/getname",
data: JSON.stringify({ name: "" }),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (data, status) {
customer = $.parseJSON(data.d);
},
failure: function (data) {
alert(data.d);
},
error: function (data) {
alert(data.d);
}
});
factory.getCustomer = function () {
return customer;
};
return factory;
});
DemoApp.controller('SimpleController', function ($scope, SimpleFactory) {
$scope.Customer = SimpleFactory.getCustomer();
});
and my view is as fallow
<html xmlns="http://www.w3.org/1999/xhtml" data-ng-app="DemoApp">
<head runat="server">
<title></title>
</head>
<body data-ng-controller="SimpleController">
<form id="form1" runat="server">
<div>
Name<input type="text" data-ng-model="Name" />{{ Name }}
<ul>
<li data-ng-repeat="customer in Customer | filter:Name">{{ customer.cust_F_name }} -
{{ customer.cust_L_name }}</li>
</ul>
</div>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="Script/Home.js" type="text/javascript"></script>
</body>
</html>
but it not working it will work fine if i hard code the data in factory but when i bring data using ajax call it will not work am unable to understand why it so.
Why it's not working?
you cannot just attach a variable to the scope when it's value is waiting for on asynchronous call.
when you use 3rd-party libraries that changes the scope you must call $scope.$apply() explicitly
prefer $http over $.ajax and use promises!
DemoApp.factory('SimpleFactory', function ($http) {
return {
getCustomer: function(){
return $http.post('Home.aspx/getname',{ name: "" });
})
}
}
DemoApp.controller('SimpleController', function ($scope, SimpleFactory) {
SimpleFactory.getCustomer().then(function(customer){
$scope.Customer = customer;
},function(error){
// error handling
});
});
If you still want to use $.ajax
you must explicitly call $scope.$apply() after the response
you must use promises or callbacks to bind to scope variables.
If you want to first fetch data from the server and than load the view
#Misko Hevery has a great answer: Delaying AngularJS route change until model loaded to prevent flicker
It's not related to your problem but load jquery before you load angular.js
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
Your problem is the js (the function "SimpleFactory.getCustomer()") is returning before AJAX call returning..
Also, you should use $http in Angular instead of jquery's ajax, because:
$http returns a "promise" similar to other areas in angular, which means .success, .done are consistent with angular.
$http set the content type to 'application/json' for you on POST requests.
$http success and error callbacks will execute inside of angular context so you don't need to manually trigger a digest cycle - if you use jQuery, then it might be necessary to call $apply..
Like this:
var DemoApp = angular.module('DemoApp', []);
DemoApp.factory('SimpleFactory', ['$http', function ($http) {
var factory = {};
factory.getCustomer = function () {
var promise = $http.post('Home.aspx/getname', {name: ''});
promise.catch(function(error) {
alert(error);
});
return promise;
};
return factory;
}]);
DemoApp.controller('SimpleController', ['$scope', 'SimpleFactory', function ($scope, SimpleFactory) {
SimpleFactory.getCustomer().then(function(customer) {
$scope.Customer = customer;
});
}]);
Factories in AngularJS are singletons. So the way you've written the code will execute the ajax call when the factory is injected into the controller. You don't see the customer data because the server response will be handled after you assign the json data to the scope variable.
A quick (and dirty) fix which will probably work is wrapping the customer object:
DemoApp.factory('SimpleFactory', function ($rootScope) {
// ...
var customer = {};
// ...
$.ajax({
// ...
success: function(data) {
$rootScope.$apply(function() {
customer.data = data;
});
}
// ...
});
});
// In view
<li data-ng-repeat="customer in Customer.data"> <!-- ... --> </li>
A better approach would be to use either to use the builtin $http or the $resource angular service. The last one requires you to make use of RESTful services (recommended). If for any reason you still want to make use of jQuery ajax calls you need some form of telling Angular that the ajax call has been completed: have a look at the $q promise service.

AngularJS: display a select box from JSON data retrieved by http GET (from REST service)

I have a REST service that I made which returns a json string which is simply a set of strings (I used Gson to generate this string (Gson.toJson(mySetOfStrings))
So I have added to my index.html:
<div ng-controller="ListOptionsCtrl">
<form novalidate>
<button ng-click="refreshList()">refresh</button>
<select name="option" ng-model="form.option" ng-options="o.n for o in optionsList></select>
</form>
</div>
and in my script:
var ListOptionsCtrl = function ListOptionsCtrl($scope, $http) {
$scope.refreshList = function() {
$http({
method: 'GET'
url: '*someurl*'
}).
success(function(data) {
$scope.optionsList = angular.fromJson(data);
});
};
}
Unfortunately all this produces in my select box is an empty list. When I see what the response to the GET request is it returns a json string with content in it so I do not see why nothing is being added to this element. What am I doing wrong here? thanks
It is because Angular does not know about your changes yet. Because Angular allow any value to be used as a binding target. Then at the end of any JavaScript code turn, check to see if the value has changed.
You need to use $apply
var ListOptionsCtrl = function ListOptionsCtrl($scope, $http) {
$scope.refreshList = function() {
$http({
method: 'GET'
url: '*someurl*'
}).
success(function(data) {
$scope.$apply(function () {
$scope.optionsList = angular.fromJson(data);
});
});
};
}
Try this.
More about how it works and why it is needed at Jim Hoskins's post
You should check for $digest error by doing if(!$scope.$$phase) { ... } before doing $apply.
success(function(data) {
if(!$scope.$$phase) {
$scope.$apply(function () {
$scope.optionsList = angular.fromJson(data);
});
}
});

Categories