【问题标题】:TypeError: (intermediate value)(intermediate value).success is not a function (angular)TypeError:(中间值)(中间值)。成功不是函数(角度)
【发布时间】:2015-07-19 12:48:49
【问题描述】:

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

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);

  });
});

这是我的 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>

我的想法是使用数据填充下拉菜单。它确实把 XML 带回来了。 任何帮助,请我现在到处都在寻找。 谢谢。

【问题讨论】:

标签: javascript angularjs angularjs-scope angularjs-controller angularjs-http


【解决方案1】:

您的$http 呼叫代码应为$http({ 而不是$http = ({,并且$log, warn 应为$log.warn

代码

$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);
});

【讨论】:

  • 另外,我读了一点,似乎使用资源而不是 HTTP 更好。我不必调用那些成功函数。如果不正确使用资源而不是 http,我的控制器会有所不同吗?
  • 不..那不正确..你所说的imllementation也可以在$http..$resource在处理REST API时也很好..
  • 我不能,还没有权限:(
猜你喜欢
  • 2021-01-13
  • 2018-02-10
  • 2022-11-04
  • 2023-01-05
  • 2023-03-09
  • 1970-01-01
  • 2016-11-06
  • 2019-07-06
  • 2018-04-02
相关资源
最近更新 更多