无法使用 Angular 读取未定义的属性“get" [英] Cannot read property 'get' of undefined with Angular
本文介绍了无法使用 Angular 读取未定义的属性“get"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Cordova 和 Angular JS 开发移动应用程序.我的应用程序位于 easyphp 本地主机上.我在 index.html 中使用带有 ng view 指令的 Angular Routes.我有这个:
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 :
类型错误:无法读取未定义的属性get"
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).我哪里错了?
If I test the URL my script returns JSON (with json_encode). Where am I wrong ?
感谢您的帮助,
问候
推荐答案
尝试改变
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
服务作为字符串传递给控制器,以便在运行时解析.
Changes:
Passing $http
service to controller as string so that will resolve at runtime.
这篇关于无法使用 Angular 读取未定义的属性“get"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文