首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >无法读取未定义with Angular的属性‘get

无法读取未定义with Angular的属性‘get
EN

Stack Overflow用户
提问于 2014-06-30 01:02:14
回答 1查看 40.1K关注 0票数 17

我正在用Cordova和Angular JS开发一个移动应用程序。我的应用程序运行在easyphp本地主机上。在我的index.html中,我使用带有ng视图指令的角度路由。我得到了这个:

TypeError:无法读取未定义的属性“”get“”

代码语言:javascript
复制
angular.module('app.controllers', [])
.controller('MainCtrl', ['$scope', function ($scope) {
    $scope.status = "Accueil";
}])
.controller('ViewCtrl', ['$scope', function ($scope, $http) {
    $http.get('mobile.php/getAnnonces/limit=10')
        .success(function(data, status, headers, config) {
          $scope.posts = data;
        })
        .error(function(data, status, headers, config) {
          // log error
    });
}])
...

如果我测试这个URL,我的脚本将返回JSON (使用json_encode)。我哪里错了?

谢谢你的帮忙,

问候

EN

回答 1

Stack Overflow用户

发布于 2014-06-30 01:06:28

试着改变

代码语言:javascript
复制
angular.module('app.controllers', [])
.controller('MainCtrl', ['$scope', function ($scope) {
    $scope.status = "Accueil";
}])
.controller('ViewCtrl', ['$scope','$http', function ($scope, $http) {
    $http.get('mobile.php/getAnnonces/limit=10')
        .success(function(data, status, headers, config) {
          $scope.posts = data;
        })
        .error(function(data, status, headers, config) {
          // log error
    });
}]);

更改:将$http服务作为字符串传递给控制器,以便在运行时解析。

票数 37
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24478293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档