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
- Chartjs not rendering chart and no error thrown
- ChartJS for 1 and 0 values display true or false
- How to display chart in android tv using web view(chart.js)
- Line Chart: background of RangeSlider
- Setting Common labels and background color common for all the charts in ChartJs
- How do you create an extension to Chart.js?
- How to edit style of negative x grid lines on Chart.js?
- base chart slice color on series value?
- Is there a way to store a chart as an image directly to server using Chart.js?
- How can I automatically rescale the y axis of my log chart using ChartJS?
- How to change the z-index of chartjs annotations label?
- Round pie chart in rectangular canvas
- Draw a mathematical function in chartjs
- ChartJS v2 custom tooltip for rLabel
- ChartJs - set x-axis ticks at specified/fixed intervals
- How to populate a charts.js pie chart using json array
- Chart.js Thick label gets replaced by three dots
- Adjust appearance of tooltip in lien chart rendered by Chart.js
- Try to change style in current month in chartJS
- Chart.js - How to set a line chart dataset as disabled on load
- chart.js break line in a label with a tooltip callback
- Chart.js: load new data on click
- Displaying line chart for multiple months using chart.js
- How to have mutiple charts in a single page using Chart.js?
- How to use the useEffect function in react js chart 2 to change the labels?
- Bar Chart With 2 Different Attribute Of The Same Variable [Chart.Js]
- Is there a max width of canvas Chart.js can draw charts within?
- Passing data in array that came from an array to chartjs with django
- Unable to display data via Charts.JS
- Using JSON in Chart.js with Angular.js