score:5
Accepted answer
The problem with your code is that json
is Promise object not the data returned from AJAX call. Also your question has "returning from AJAX request" aspect. Make sure you understand related problem, check this very popular question.
Proper way to set scope data retrieved with AJAX request in Angular is to do it inside then callback:
app.controller('jsonServerBox', function ($scope, $http) {
$http.get('serverbox.json').then(function (res) {
$scope.ocw = res.data;
});
});
score:4
In you case json
variable is nothing but it contains promise object.
And Promise should always be resolve using .then
CODE
var json = $http.get('serverbox.json').then(function(res) {
return res.data;
});
json.then(
//success callback
function(data) {
$scope.ocw = data
},
//error callback
function() {
//error handling
})
});
This would help you.
Thanks.
Source: stackoverflow.com
Related Query
- Load JSON to display data, using ng-repeat {ANGULAR.JS}
- How to display chart using Chartjs with JSON data in Laravel
- load external json data file in to chartjs in the angular component
- How to display Json object in chart js consisting of lists created using Django rest framework in angular application
- Weather graph using Angular 2, chart.js and json data
- Chart.js load new data from saved JSON object
- Using JSON file data in Chart.js
- Beginner using chart.js: having trouble display state full of data into a column chart using variables
- Angular / ng2-charts: Fetching json data in chart object showing: Cannot read property 'length' of undefined
- format JSON data for chart.js from Angular 4 observable
- Angular 2: How to pass my API data to graph and Display the Graph with data
- Load data from a JSON object into an array
- Using two JSON objects to make Chart.JS Bar Chart Dynamic in Typescript / Angular
- How do I display chart on my HTML page based on JSON data sent by Node JS
- Populating Chart.Js line graph with multiple lines using data from a JSON Object
- Receiving json data from a server to display a chart.js graph not working
- How to send data to chart js using angular
- How to get Data from API to display chart using chartjs in Vuejs
- how can plot graph using json data
- How can i display my data in a chart using chart js
- To display data from mock server into chartjs using ember
- Chart.js using json data
- How to display the values inside the pie chart of PrimeNG (chart) using JavaScript or Angular
- Chart.js using json data from MySQL
- ionic display chartjs data from json http request
- Plotting JSON data onto a chart using Chart.js
- How can I display `Null` value data on Y Axis using the Primitive dataset format in Chart.js V3.7.0?
- How can I process json file and display some data in form of charts in django
- Angular 2+: How to load a data to chartjs graph in every second in Angular
- Angular how to display data inside every part of doughnut chartjs
More Query from same tag
- React-Chartjs-2 and Chartjs v3:Option Property
- cannot read property 'yyyx' of undefined
- Chart.js 2.0 - vertical lines
- Chart.js Show Label near Line in combined Chart
- Chart.js how to rewrite x for webAPP
- Building a 24h visualisation with chartjs
- show label in tooltip but not in x axis for chartjs line chart
- Links in bar charts (charts.js)
- How to retain spacing between bars for two different bar charts in Chart.js 2
- Chart.js "display:none" Issue
- Call chartjs in rhino using java
- Customised tooltip in chart.js
- How to load a chart in a diferent page
- c# Chart.Js and JSON with NewtonSoft
- Chart.JS Display 5 largest values in the legend
- Can JS lib can be use in Native Tizen App?
- Data not fully displaying on bar chart
- Method inside Activate in Aurelia
- How to change background color of labels in line chart from chart.js?
- Chart JS tooltip appears differently when set from script instead of html
- Adding label inside multiseries doughnut chart through chart.js
- When I try to include the chart.js and angular chartjs files, I get: ReferenceError: require is not defined
- How do I use this new extension for chart.js?
- How to add text inside the doughnut chart using Chart.js version 3.2.1
- Create an interactive custom tooltip for chartjs
- How to Remove axis Lines from chart in chart js
- Chart.js - show tooltip when hovering on legend
- Chart.js "minBarLength" not working as intended?
- Chart.js 3.x custom positioners: cannot use them in TypeScript
- Charts.js in Angular 7 - working with imported time for timeseries