Javascript TypeError: (intermediate value)(intermediate value).success 不是函数(角度)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30126612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:42:38  来源:igfitidea点击:

TypeError: (intermediate value)(intermediate value).success is not a function (angular)

javascriptangularjsangularjs-scopeangularjs-controllerangularjs-http

提问by kkdeveloper7

I have difficulties understanding this error... I dont quite understand why its not a function....

我很难理解这个错误......我不太明白为什么它不是一个函数......

angular.module('mkApp').factory('mkService', function ($http, $log) {
  function getLookUp(successcb) {
    $http = ({
        method: 'GET',
        url: 'api/Entries/'

    }).success(function (data, status, header, config) {
        successcb(data);
    }).
    error(function (data, status, header, config) {
        $log, warn(data, status, header, config);
    });
  };

  return {
    lookUp: getLookUp
  }
});

angular.module('mkApp').controller('mkControler', function ($scope, mkService) {
  mkService.lookUp(function (data) {
    $scope.ddl = data;
    console.log(ddl);

  });
});

And here is my HTML

这是我的 HTML

<div ng-app="mkApp">
    <div ng-controller="mkControler">            
       <table>
           <tr>
               <td> First Name</td>
               <td> Last Name</td>
           </tr>
           <tr>
               <td><input type="text" /></td>
               <td><input type="text" /></td>
           </tr>
           <tr>
               <td>
                   <select></select>
               </td>
           </tr>
       </table>

    </div>
</div>

My idea is to use data to populate drop down. It does bring me XML back. Any help please i've been looking everywhere now. Thank you.

我的想法是使用数据来填充下拉列表。它确实让我回到了 XML。任何帮助,我一直在到处寻找。谢谢你。

回答by Pankaj Parkar

Your $httpcall code should be $http({instead of $http = ({and also $log, warnshould be $log.warn

您的$http通话代码应该是$http({不是$http = ({$log, warn应该$log.warn

Code

代码

$http({
    method: 'GET',
    url: 'api/Entries/'
}).success(function (data, status, header, config) {
    successcb(data);
}).
error(function (data, status, header, config) {
    $log.warn(data, status, header, config);
});