【问题标题】:Data retrieving Using Rest Web services by angular js is not happing通过 angularjs 使用 Rest Web 服务检索数据没有发生
【发布时间】:2015-09-06 22:52:31
【问题描述】:

这是应用的代码部分

  <div class="container" data-ng-app="myApp" ng-controller="hController">
  <li ng-repeat="x in names">
        {{ x.Name + ', ' + x.Country }}
    </li>
    </ul>

控制器实现

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://localhost:8080/rest/hotel")
.success(function(response) {$scope.names = response.records;});
});
</script>
</head>

我可以在 Web 控制台中看到错误

错误:[ng:areq] http://errors.angularjs.org/1.3.14/ng/areq?p0=hotelController&p1=not%20a%20function%2C%20got%20undefined 在错误(本机) 在http://localhost:8080/resources/js/angular.min.js:6:417

我已经在路径中添加了 angular.min.js

【问题讨论】:

  • 控制器的名字是customersCtrl,更改ng-controller

标签: ajax angularjs rest


【解决方案1】:

控制器命名冲突

  app.controller('customersCtrl'....) 

在模板中你使用了“hController”

 <div class="container" data-ng-app="myApp" ng-controller="hController">

在两个地方使用相同的名称,否则 angular 找不到模板中定义的指令 ng-controller 并因此产生错误 out 。 ng-controller 是一个 Angular 内置指令,它将控制器附加到视图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-02
    • 2018-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多