AngularJS Tutorial #17- JSON and $http

  Рет қаралды 85,010

Net Ninja

Net Ninja

Күн бұрын

Пікірлер: 116
@neenaw
@neenaw 7 жыл бұрын
If you are having trouble try: $http.get('data/ninjas.json').then(function(response){ $scope.ninjas = response.data; }); Angular just changes a little over time.
@SimPwear84
@SimPwear84 7 жыл бұрын
Every new update /version they might change how things are done. Just follow the tutorial series using version 1.5 You can later learn how to do the same thing with a later version
@BrunolFornazari
@BrunolFornazari 7 жыл бұрын
The reason is that in 1.6+ versions of angular.js, the method get returns a promise instead of any XHR response object as older versions did
@warchild2726
@warchild2726 7 жыл бұрын
You are lifesaver
@marcello4050
@marcello4050 6 жыл бұрын
Mah man, You're a hero
@xlong2842
@xlong2842 4 жыл бұрын
Thank u sir
@jheelmonty
@jheelmonty 6 жыл бұрын
For the newcomers in AngularJS. While using AngularJS 1.6v a bit of syntax is changed. You need to write this: $http.get('data/ninjas.json').then(function(response) { $scope.ninjas = response.data; }); instead of this: $http.get('data/ninjas.json').success(function(data) { $scope.ninjas = data; });
@sandiledamuziqal909
@sandiledamuziqal909 9 ай бұрын
i have a problem, I can push data into JSON but when I refresh the page the data disappears I want to store the data forever in the JSON file
@frootEpebbles
@frootEpebbles 8 жыл бұрын
I'm new to Angular and happened to stumble upon this video, I learned so much that I'll check out the rest of this series and subscribe to your channel. Thanks so much!
@moaazbhnas886
@moaazbhnas886 6 жыл бұрын
Hey guys, .success() is deprecated. use .then() instead. When you use this method, it passes a complete HTTP response which contains the data we want to the callback function instead of just the data. To retrieve data from that response: $http.get('data/friends.json').then(function(response) { $scope.friends = response.data; }); Good Luck!
@sandiledamuziqal909
@sandiledamuziqal909 9 ай бұрын
i have a problem, I can push data into JSON but when I refresh the page the data disappears I want to store the data forever in the JSON file
@andreiaquino8994
@andreiaquino8994 5 жыл бұрын
Hi the net ninja, thanks for the clear explanation. This is GOLD :) I got few errors when I used the codes in the video. This fixed the app in my machine: - change ".success" to ".then" - array problem when loading the $scope.ninjas = data; , so i console.log() the object, I ended up using $scope.ninjas = data.data; Thanks again! :)
@thekuzicartoon
@thekuzicartoon 4 жыл бұрын
ya, data.data worked for me. along with then instead of success. I am using angular v1.8.0
@chaseklingel9080
@chaseklingel9080 8 жыл бұрын
Your videos are great! Thank you for taking the time to put this together.
@Atpugtihsrah
@Atpugtihsrah 8 жыл бұрын
Hi, After making the changes suggested by Pablo, my code gave the error which said something like "json file must be an Array to orderBy to work." But my json file was already with-in the [ {}, {}, {} ] (Array braces). Looking further, I found that the data being sent is actually an object which has 2 properties 'config' and 'data' out of which 'data' was an array. So, after further changing the code to data.data, it worked. Finally, something like : $http.get('data/employees.json').then(function(data){ //console.log(data); $scope.employees = data.data; }); Let me know if I'm wrong somewhere :) Thanks.
@MrChachoo
@MrChachoo 8 жыл бұрын
check out the comment by Hendra Widjaja above.
@lungisanigwala4973
@lungisanigwala4973 5 жыл бұрын
I can tell you.. it works my guy
@edwinaritama
@edwinaritama 5 жыл бұрын
i tried yours, and it works on me thanks
@NitinGupta-hu1sy
@NitinGupta-hu1sy 6 жыл бұрын
Thank you. I have worked on angularjs. Your tutorial are very easy and straight forward. Had good revision.
@mariavillanueva9576
@mariavillanueva9576 7 жыл бұрын
this one works for the success method error and the array thing $http.get('data/ninjas.json').then(function (response) { $scope.ninjas = response.data; });
@reut1990
@reut1990 6 жыл бұрын
very helpfull:)
@Yv3tt3u
@Yv3tt3u 6 жыл бұрын
Thanks! This worked for me.
@JeremiahKellogg
@JeremiahKellogg 6 жыл бұрын
Yes! Thank You!
@selvoselvo1
@selvoselvo1 6 жыл бұрын
yap also had "success is not a function", works this way
@rishabhpatel263
@rishabhpatel263 6 жыл бұрын
that indeed worked thanks. But can you tell me why we are writing response.data instead of just response.
@binayakgshankar9188
@binayakgshankar9188 6 жыл бұрын
What an explanation. U saved my job, man !
@samuelbitrus1667
@samuelbitrus1667 7 жыл бұрын
hey guys if you did everything correctly and you are still getting an error, try renaming your json file from ninjas.json to something else. it worked for me. Cheers
@inframatic
@inframatic 7 жыл бұрын
Your source files are empty, with no sign of JS. Am I missing something?
@roryangus1480
@roryangus1480 6 жыл бұрын
Hi, the code in the tutorial is for an older version of Angular. If you want to understand the issue and also how to fix it, then have a look at this thread... stackoverflow.com/questions/41169385/http-get-success-is-not-a-function The code below works and also has some call error handling features. Have a play with different scenarios such as; The file name correct, file name incorrect, corrupt JASON data by adding some '//' to the first line of the JSON file to stop it working. Look at the different error messages you get and the different objects that are output to the console. $http.get('data/ninjas.json').then(successCallback, errorCallback); function successCallback(response){ //success code $scope.ninjas = response.data; console.log(response, 'Data that was in the successful response call'); //outputs a value to the console. Inspect element to see it. alert("Got the data!"); //outputs a value to the user on the screen } function errorCallback(error){ //error code console.log(error, 'Can not get data.'); //outputs a value to the console. Inspect element to see it. alert("Can not get the data - Check the JSON file is valid"); //outputs a value to the user on the screen }
@amazinghenry8893
@amazinghenry8893 3 жыл бұрын
much better
@CipriValdezate
@CipriValdezate 8 жыл бұрын
Very good tutorial! Good work, we are grateful!
@quanlamtruong5870
@quanlamtruong5870 6 жыл бұрын
the best tutor video so far
@theRINspace
@theRINspace 5 жыл бұрын
If some of you guys have issues having with console.logging the JSON data, make sure you're on the ninja list page instead of the homepage.
@arabbatehafsa7526
@arabbatehafsa7526 3 жыл бұрын
how to add a new ninja in the json file using the form ?
@AVYFLUX
@AVYFLUX 5 жыл бұрын
In case anyone is watching this now... the $htpp.success() method is deprecated and might throw errors. The following code can be used instead... $http.get('data/ninjas.json').then(function (response){ console.log(response.data) $scope.ninjas = response.data; },function (error){ });
@bluesinmahblood
@bluesinmahblood 5 жыл бұрын
Spent a couple of hours yesterday trying to debug this.
@funtravellers7754
@funtravellers7754 7 жыл бұрын
very nice tutorial
@bijay7
@bijay7 8 жыл бұрын
Hey Shaun, thanks for this awesome course, I have a query though I used the code $http.get('data/ninjas.json').then(function(response){ $scope.ninjas = response.data; }); as suggested in few comments below but still for me ninja list is not getting displayed. But when I change $http.get('data/ninjas.json') to $http.get('ninjas.json') and put ninjas.json it works. No idea why, I tried this with Brackets also and still the same thing, anyone any idea why??
@shubhamgarde6830
@shubhamgarde6830 7 жыл бұрын
hello, you insert the file locaton of your ninjas.json eg: i stores my json file in C:/xampp/htdocs/project/js/ninjas.json so i will insert the location as $http.get("js/ninjas.json") so basically, you dont have a folder named data so angular is not able to find the json file
@sandiledamuziqal909
@sandiledamuziqal909 9 ай бұрын
i have a problem, I can push data into JSON but when I refresh the page the data disappears I want to store the data forever in the JSON file
@poul_yvarov
@poul_yvarov 8 жыл бұрын
Thank you! Very useful!
@rutpshah
@rutpshah 7 жыл бұрын
Getting below error when I did this using different data: angular.js:14516 Error: [orderBy:notarray] Expected array but received: {"data":[{"name":"orange","vitamin":"C","price":100,"available":true},{"name":"apple","vitamin":"A","price":200,"available":true},{"name":"watermelon","vitamin":"B","price":2000,"available":true}],"status":200,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"data/fruits.json","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":"OK"} errors.angularjs.org/1.6.3/orderBy/notarray?p0=%7B%22data%22%3A%5B%7…son%2C%20text%2Fplain%2C%20*%2F*%22%7D%7D%2C%22statusText%22%3A%22OK%22%7D at angular.js:66 at angular.js:22206 at fn (eval at compile (angular.js:15351), :4:300) at regularInterceptedExpression (angular.js:16459) at Scope.$digest (angular.js:18002) at Scope.$apply (angular.js:18280) at done (angular.js:12378) at completeRequest (angular.js:12604) at XMLHttpRequest.requestLoaded (angular.js:12532)
@timojedai6576
@timojedai6576 7 жыл бұрын
Same problem and no way to resolve it :/
@sarthaksaxena1093
@sarthaksaxena1093 6 жыл бұрын
$http.get("data.json").then(function(data){ console.log(data.data); $scope.ninjas = data.data; }) Do this
@oscardbg9654
@oscardbg9654 5 жыл бұрын
@@sarthaksaxena1093 thanks, the success function no longer works, use then instead and data.data solves the problem
@devonterobinson1842
@devonterobinson1842 8 жыл бұрын
I have tried this Node.js and got a cross site scripting error. How are you accessing the Json file?
@paritoshfulara
@paritoshfulara 7 жыл бұрын
Hey Shaun, how can we get the JSON data from a node server using http service? Instead of having a data In some file can we get the directly from the node response object
@basith237
@basith237 5 жыл бұрын
don't forget to check the data after fetch with $http by console.log(data). if the result of your response give the object (response status, header, statusText and data), you must modify like this to get all ninjas data $scope.ninjas = data.data
@abhineet3695
@abhineet3695 6 жыл бұрын
For angular 1.6.x use: $http.get('data/ninja.json') .then(function(success){ $scope.ninjass = success.data; }, function(error){ console.log("error loading ninja.json"); });
@visibletoanyone1508
@visibletoanyone1508 5 жыл бұрын
I used .success as well as .then but none of the above shows the list. Can you help me where I am stuck?
@darkthrongrising5470
@darkthrongrising5470 7 жыл бұрын
I have been trying to do this with an actual service function(all three variations) in order to keep my controller out of the business logic. Ive not had much luck yet, could you point me in the right direction on that? Now I realize that I should just do what works but Im just trying to get a better feel for (custom)services. I nailed routes first try and it has been said that routing is the most confusing aspect, I have personally found services much more complicated. But yeah, right on for the video, ur stuff is always helpful.
@thegreenman9000
@thegreenman9000 5 жыл бұрын
For modern versions of Angular use: " $http.get('data/ninjas.json') .then(function sucessCallback(response){ $scope.ninjas = response.data; }, function errorCallback(response){});"
@naveenspv
@naveenspv Жыл бұрын
we are getting data in json format how it is parsed as an object
@tubeMonger
@tubeMonger 8 жыл бұрын
Would it be possible to create a custom service and make reusable $http functions for GET and POST to be used in controllers?
@shubhamgarde6830
@shubhamgarde6830 7 жыл бұрын
I want to retrieve a single entry , like enter and ID and everything related to that ID is retrieved. HOW DO I DO IT?
@ivandelvalleabuja2220
@ivandelvalleabuja2220 5 жыл бұрын
Did you solve it?
@JamesJohnAgar
@JamesJohnAgar 7 жыл бұрын
What about connecting to backend databases ?
@Nickopanther00
@Nickopanther00 5 жыл бұрын
If anyone is working in Angular JS 1.7+ and you're having an issue with the code: $http.get('data/ninjas.json').success(function(data) { $scope.ninjas = data } then type it this way instead: $http.get('data/ninjas.json').then(function(response) { $scope.ninjas = response.data; });
@thecodecatalyst
@thecodecatalyst 5 жыл бұрын
Use then instead of success in versions +1.6
@sandiledamuziqal909
@sandiledamuziqal909 9 ай бұрын
i have a problem, I can push data into JSON but when I refresh the page the data disappears I want to store the data forever in the JSON file
@ddaki
@ddaki 8 жыл бұрын
i have question.... i did everything like you in this tutorial (and others also)...and my app is not runing when i add http service. in controller..i'm getting error... Error: $http.get(...).success is not a function but if i change success with "then"and in function pass response and in $scope.ninjas "save" response.data then it works..do you know why????
@nexsklrs
@nexsklrs 8 жыл бұрын
look at the comment from @Pablo Zabala
@hendrawidjaja490
@hendrawidjaja490 8 жыл бұрын
/* Simple GET request example with promises */ $http({ method: "GET", url: "./data/ninjas.json" }).then(function successCallback(response) { /* this callback will be called asynchronously when the response is available */ $scope.ninjas = response.data; }, function errorCallback(response) { /* called asynchronously if an error occurs or server returns response with an error status. */ console.log("Error " + response.status + ": " + response.data) }); Don't forget to add $http on the controller
@AsheeshChaudhary
@AsheeshChaudhary 8 жыл бұрын
The .success and .error methods are deprecated and have been removed from AngularJS 1.6. Use the standard .then method instead.
@hendrawidjaja490
@hendrawidjaja490 8 жыл бұрын
any life example or code?
@leonardoholanda3879
@leonardoholanda3879 7 жыл бұрын
Hi, I try $http({ method: "GET", url: "data/ninjas.json" }).then(function successCallback(response) { $scope.greeting = response.data; }, function errorCallback(response) { console.log("Error " + response.status + ": " + response.data) }); and console return angular.js:10514 XMLHttpRequest cannot load file:///C:/Users/ideia/Workspace/Angular/estudos_com_angular_1/aula-comecando-com-angularjs-master/data/greeting.json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension. what am i doing wrong?
@harshitha94
@harshitha94 6 жыл бұрын
i have a query in redis connection to nodejs .. can i find some help
@fffhshf345
@fffhshf345 5 жыл бұрын
I have a problem, it does not show ninjas on my directory view. Any tips?
@MrUaliev
@MrUaliev 5 жыл бұрын
try using .then instead of .success when you get data from http. Also in the function it should be $scope.ninjas = response.data; (not just data, you should access it) I guess it's the differences between older and newer versions of angularjs
@ChongDelro
@ChongDelro 8 жыл бұрын
i tried but when I go to the list of ninjas it shows nothing anymore....
@AsheeshChaudhary
@AsheeshChaudhary 8 жыл бұрын
The .success and .error methods are deprecated and have been removed from AngularJS 1.6. Use the standard .then method instead.
@chetanbhat77
@chetanbhat77 6 жыл бұрын
"TypeError: $http.get(...).success is not a function angular.min.js:125" getting this error on the console, the data is not being displayed.
@shajahanj2646
@shajahanj2646 6 жыл бұрын
use .then
@briangoodman9169
@briangoodman9169 8 жыл бұрын
Hmm printing to the console didn't work for me
@XFDW
@XFDW 7 жыл бұрын
I'm getting this weird error I was hoping you can help me with.. the error is " Error: [orderBy:notarray]". Can anyone help with this?? It only appeared after I moved the array to the $http service
@shaikhabdulsohail3982
@shaikhabdulsohail3982 5 жыл бұрын
use .then instead of success for latest version in order to overcome this error - "$http.get(...).success is not a function"
@larsvargstrand6749
@larsvargstrand6749 7 жыл бұрын
Like many said, ".success" is deprecated, ".then"... instead. Like so: $http.get('data/ninjas.json').then(function(response){ $scope.ninjas = response.data; More info at stackoverflow.com/questions/35329384/why-are-angular-http-success-error-methods-deprecated-removed-from-v1-6
@mkaufmandev
@mkaufmandev 8 жыл бұрын
The heck is Haitch-ttp?
@Spok2go
@Spok2go 8 жыл бұрын
Foonction, Heitch-ttp
@alexpham481
@alexpham481 7 жыл бұрын
LOL, great video tho.
@ПавелЕфименко-й1п
@ПавелЕфименко-й1п 7 жыл бұрын
just wait till he say "bhhhowser") just funny english accent)
@explosoratory
@explosoratory 6 жыл бұрын
I had two errors on this tutorial and found a solution for this. I share that for the people like me. >< * Error 1. there is no function $http.get(..).suceess * Solution. please change 'success to then' like below. $http.get('data/ninjas.json').then(function(data){ * Reason. you might use updated version. ----------------------------------------------------------------------------------------------------------------- * Error 2. orderBy:notarray JSON * Solution. Change $scope.ninjas = data; to $scope.ninjas = data.data; * Reason - I found this on stackoverflow. ng repeat works with an arrays but as per the response getting from the API in then() method is not the data itself but it is having a property named as data which is the actual array that you have to pass in ng-repeat. (stackoverflow.com/questions/41315423/expected-array-but-received-json-angularjs-error) ++ Thank you Ninja, this video is really helpful. ;)
@FavouriteVid
@FavouriteVid 4 жыл бұрын
your reply helps :) thanks for the extra details
@AgungPrasetyo2112
@AgungPrasetyo2112 6 жыл бұрын
$http.get('data/ninjas.json') can we write source from external domain/server, like $http.get('otherdomain/data/ninjas.json') ??
@asimov1979
@asimov1979 5 жыл бұрын
For anyone using later versions of AngularJS stackoverflow.com/questions/41169385/http-get-success-is-not-a-function
@Desdroyer24
@Desdroyer24 5 жыл бұрын
Today July 16th , 2019 $http.get().success.(...) is obsolete, with angular version > 1.6, and actually 1.7, instead use: $http.get('path') .then(function(response) { $scope.ninjas = response.data; });
@PabloZabala1820
@PabloZabala1820 8 жыл бұрын
HI, anohter way is to use "then" function to capture the possible error.... $http.get("url", dataToSend).then( function(response) { // Success!!! $scope.ninjas = response; }, function(error) { // a 500 error ocurred or any other.... $scope.ninjas = []; // throw error message.... }); Sory for my english ;)
@Kirst817
@Kirst817 8 жыл бұрын
The .success has been deprecated.
@OMGDrAcula
@OMGDrAcula 8 жыл бұрын
Since it has been deprecated, is what Pablo posted the correct way to do the request now?
@glennesavage7443
@glennesavage7443 8 жыл бұрын
Using .then instead of .success is actually straight forward. Swap out Ninja's http request code from the video with this: $http.get('data/ninjas.json').then(function(response){ $scope.ninjas = response.data; });
@kintarooe575
@kintarooe575 8 жыл бұрын
Thank you so much! This solved my problem!
@locus1289
@locus1289 4 жыл бұрын
Hwoah!
@runthecode_
@runthecode_ 2 жыл бұрын
$http.get("data/sites.json").then( function successCallback(response) { $scope.sites = response.data; }, function errorCallback(response) { console.error(response); } );
@moeidsaleemkhan7233
@moeidsaleemkhan7233 8 жыл бұрын
404 error
@theredcrafteryt6130
@theredcrafteryt6130 6 жыл бұрын
TypeError: $http.get(...).success is not a function.
@theredcrafteryt6130
@theredcrafteryt6130 6 жыл бұрын
Angular V6, Brackets text editor(Atom Broke :( )
@theredcrafteryt6130
@theredcrafteryt6130 6 жыл бұрын
NVM I got it $http.get was deprecated sense Angular 1.5 you now have to use $http.get().then();
@victorfuentesmenes2462
@victorfuentesmenes2462 6 жыл бұрын
use this: $http.get('data/ninjas.json').then(function(response){ $scope.ninjas = response.data; });
@bimalgrg8951
@bimalgrg8951 8 жыл бұрын
Please control while hitting Enter key... m watching tutorials with headphone :(
@pietrononame4945
@pietrononame4945 Жыл бұрын
It is not working now the way shown in the video, i.e. right syntax should be like: $http.get('/someUrl', config).then(successCallback, errorCallback);
@bijoymogor
@bijoymogor 2 жыл бұрын
// Simple GET request example: $http({ method: 'GET', url: 'data/ninjas.json' }).then(function successCallback(response) { // this callback will be called asynchronously // when the response is available $scope.ninjas = response.data; console.log($scope.ninjas); }, function errorCallback(response) { // called asynchronously if an error occurs // or server returns response with an error status. });
@mukunth7395
@mukunth7395 21 күн бұрын
new latest syntax $http.get('data/ninjas.json').then(function(response){ $scope.ninjas = response.data; });
AngularJS Tutorial #18 - Custom Directives
17:43
Net Ninja
Рет қаралды 57 М.
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,3 МЛН
Their Boat Engine Fell Off
0:13
Newsflare
Рет қаралды 15 МЛН
Air Sigma Girl #sigma
0:32
Jin and Hattie
Рет қаралды 45 МЛН
She wanted to set me up #shorts by Tsuriki Show
0:56
Tsuriki Show
Рет қаралды 8 МЛН
AngularJS Http Get Service to Fetch JSON Data Example
7:29
Coding Shiksha
Рет қаралды 7 М.
AngularJS Tutorial #16 - Views and Routes
12:29
Net Ninja
Рет қаралды 69 М.
AngularJS Tutorial #20 - Animations (part 1)
13:32
Net Ninja
Рет қаралды 43 М.
AngularJS HTTP Post JSON Example
15:46
Coding Shiksha
Рет қаралды 9 М.
AngularJS Tutorial #22 - Form Validation (part 1)
12:27
Net Ninja
Рет қаралды 57 М.
$http service in AngularJS
11:38
kudvenkat
Рет қаралды 313 М.
APIs for Beginners - How to use an API (Full Course / Tutorial)
2:19:33
freeCodeCamp.org
Рет қаралды 4,5 МЛН
AngularJS Http Request Tutorial
6:39
Jake Cyr
Рет қаралды 1,7 М.