javascript - AngularJS $http 不起作用?

标签 javascript angularjs

我是 AngularJS 的新手,我想检索 html 页面中的所有产品,但即使“/allProd”在没 Angular 情况下完美工作,它也不会显示任何内容

app.js

var app=angular.module('crm',[]);
app.controller('CRMController', function($scope,$http){
  $scope.products=[];
  $http.get('/allProd')
    .then(function(data){
        $scope.products=data;
    });
});

index.html

<html data-ng-app="crm" >
<head>
  <meta charset="ISO-8859-1">
  <title>Catalog</title>
  <link rel="stylesheet" type="text/css" href="bootstrap-3.3.4-dist/css/bootstrap.min.css"/>    
  <link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body data-ng-controller="CRMController">
  <table class="table">
    <thead>
      <tr>
        <th> REF </th><th> DES </th><th> PRICE </th>
      </tr>
    </thead> 
    <tbody > 
      <tr data-ng-repeat="p in products.content">
        <td>{{p.reference}}</td> 
        <td>{{p.designation}}</td>
        <td>{{p.price}}</td>
      </tr>
    </tbody>
  </table>

<script type="text/javascript" src="angular/angular.min.js"></script>
<script type="text/javascript" src="angular/angular-sanitize.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>

What i got

PS:我使用的是 Angular 1.5.6 和 spring-boot 1.5.2.RELEASE

最佳答案

根据documentation for $http实际的响应正文位于响应的 data 属性中。

$http.get('/allProd')
.then(function(response){
    $scope.products = response.data;
});

关于javascript - AngularJS $http 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43219580/

相关文章:

javascript - 如何可视化是/否数据

javascript - 在 Angular 2 上显示来自其他组件的模态组件

angularjs - 如何使用angularJS拦截器只拦截特定的http请求?

javascript - $timeout 不是函数 angularjs

angularjs - 如果 src 不存在,则从 dom Angular 删除元素

javascript - ng-click <tr> 不执行任何操作

javascript - 动态添加按钮d3.js

javascript - 在两个窗口中打开页面

javascript - 类型错误 : Cannot read property '0' of undefined

javascript - 避免在 AngularJS 的不同 Controller 中重复作用域变量