I have a question: Can you use then()
on any function?
In my Angular app, I'm encountering an error ('cannot read property then of undefined') when attempting to utilize then
.
For instance, take this function:
self.getCommentsData = function() {
commentsService.getComments($routeParams.id)
.then(function (data){
//Perform some operations and finally push to a scope array
$scope.commentsList.push(someValue);
});
}
Later on, I want to invoke this method and only proceed with another line of code once it has completed. This is where I'm using the then
:
self.getCommentsData()
.then(function(){
$location.hash('goTotrue');
$anchorScroll();
});
However, I am running into an error - not sure what I'm missing here.
Thank you