angularjs - Angular .js :14642 TypeError: Cannot read property 'then' of undefined when calling back-end service from angular

标签 angularjs node.js angular-promise

我正在使用 Angular 调用后端服务,但遇到错误。响应到达我的服务,但由于上述 promise 错误,我无法从那里获得对我的 Angular Controller 的响应。

angular.service

function userRegister(data) {
  $http.post('/api/user/register',data).then(function(response) {
    console.log(response); //the success response comes here
    return response;
  });
}

Angular Controller

vm.register = function register() {
  console.log(vm.user);

  commonService.userRegister(vm.user).then(function (response) {
    console.log(response); //the promise error comes here
  });
}

有人可以帮我解决这个问题吗?

最佳答案

您还应该退回您的服务

function userRegister(data) {
 return $http.post('/api/user/register',data).then(function(response) {
    console.log(response); //the success response comes here
    return response;
  });
}

关于angularjs - Angular .js :14642 TypeError: Cannot read property 'then' of undefined when calling back-end service from angular,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44904408/

相关文章:

node.js - Typeorm 给我 QueryFailedError : column reference "id" is ambiguous

javascript - 带延迟的递归函数

AngularJS 2 a Promise resolve 在 feching 时丢失类标识

javascript - angularjs 链接 promise 不起作用,而 angular.copy 也不起作用

javascript - 无法在运行时在 Jenkins 中安装 NodeJS

angularjs - columnFilter 插件不适用于 Angular DataTables 服务器端处理

javascript - AngularJs 过滤器

javascript - 使用 ng-pattern 的多封电子邮件的正则表达式

google-maps - ng-click 在谷歌地图的信息窗口内容中

node.js - 如何关闭可读流(结束前)?