未定义与角不能读取属性'得到' [英] Cannot read property 'get' of undefined with Angular

查看:115
本文介绍了未定义与角不能读取属性'得到'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发展与科尔多瓦和角度JS移动应用。我的应用程序是在一个本地主机的EasyPHP。
我用角路线,在我的index.html一个NG观点指令。而且我有这样的:


  

类型错误:未定义无法读取属性'得到'


  angular.module('app.controllers',[])
.controller('MainCtrl',['$范围',函数($范围){
    $ scope.status =ACCUEIL;
}])
.controller('ViewCtrl',['$范围',函数($范围,$ HTTP){
    $ http.get('mobile.php / getAnnonces /限额= 10')
        .success(功能(数据,状态,头,配置){
          $ scope.posts =数据;
        })
        .error(功能(数据,状态,头,配置){
          //记录错误
    });
}])
...

如果我测试URL我的脚本返回JSON(与json_en code)。我在哪里错了?

感谢您的帮助,

问候


解决方案

试图改变

  angular.module('app.controllers',[])
.controller('MainCtrl',['$范围',函数($范围){
    $ scope.status =ACCUEIL;
}])
.controller('ViewCtrl',['$范围,$ HTTP',函数($范围,$ HTTP){
    $ http.get('mobile.php / getAnnonces /限额= 10')
        .success(功能(数据,状态,头,配置){
          $ scope.posts =数据;
        })
        .error(功能(数据,状态,头,配置){
          //记录错误
    });
}]);

的变化:
通过 $ HTTP 服务控制器作为字符串,以便在运行时解决。

I'm developing a mobile app with Cordova and Angular JS. My app is on an easyphp localhost. I use Angular Routes with a ng view directive in my index.html. And I've got this :

TypeError: Cannot read property 'get' of undefined

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
    });
}])
...

If I test the URL my script returns JSON (with json_encode). Where am I wrong ?

Thanks for your help,

Regards

解决方案

try to change

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

Changes: Passing $http service to controller as string so that will resolve at runtime.

这篇关于未定义与角不能读取属性'得到'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆