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 :
我正在使用Cordova和Angular JS开发移动应用程序。我的应用程序位于easyphp localhost上。我在index.html中使用带有ng视图指令的Angular Routes。我有这个:
TypeError: Cannot read property 'get' of undefined
TypeError:无法读取未定义的属性'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
});
}])
...
If I test the URL my script returns JSON (with json_encode). Where am I wrong ?
如果我测试URL我的脚本返回JSON(使用json_encode)。我哪里错了?
Thanks for your help,
谢谢你的帮助,
Regards
问候
1 个解决方案
#1
37
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.
更改:将$ http服务作为字符串传递给控制器,以便在运行时解析。
#1
37
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.
更改:将$ http服务作为字符串传递给控制器,以便在运行时解析。