when should we use .then when we receive an object from function

More
11 months 1 week ago #67 by msramesh12
msramesh12 created the topic: when should we use .then when we receive an object from function
1) I want to understand why the two lines of code highlighted in BOLD letters wont work and i have to use the .then function to make it work?
2) also can you explain these syntax in a detailed way to that we understand when to use .then...etc?


var app = angular.module("myModule", []);
app.controller("myCtrl", function ($scope, myWebServices) {

myWebServices.Comments().then(function (returnedData) {
$scope.myComments = returnedData;
console.log($scope.myComments);
});
//$scope.myComments = myWebServices.Comments();
//console.log($scope.myComments);
});

app.service("myWebServices", function ($http) {
this.Comments = function () {
var abc = $http.get(" jsonplaceholder.typicode.com/comments ").then(function (Response) {
return (Response.data);
})
return abc;
}
});

Please Log in or Create an account to join the conversation.

More
11 months 1 week ago - 11 months 1 week ago #68 by Srilakshmi Mallavolu
Srilakshmi Mallavolu replied the topic: when should we use .then when we receive an object from function
Please login to view the answers
Last Edit: 11 months 1 week ago by Srilakshmi Mallavolu.
The following user(s) said Thank You: Babloo

Please Log in or Create an account to join the conversation.

Time to create page: 0.194 seconds
Powered by Kunena Forum