我试图从Reddit的JSON API(RedditUrl.json)中检索信息并在我的Ionic Creator App上显示。我通过输入{{variable}}绑定了HTML和JS,因此不是问题所在。除此之外,我在I' m工作的组件上键入了Angular Directives:
ng-app = "ionicApp" ng-controller = "MainCtrl"
实际JS代码:
function ($scope, $stateParams) {
console.log('Mert');
angular.module('ionicApp', [])
.controller('MainCtrl', function($scope, $http) {
$http.get('https://www.reddit.com/r/worldnews.json').then(function(resp) {
$scope.title = resp.data.title;
$scope.num_comments = resp.data.num_comments;
$scope.ups = resp.data.ups;
console.log('Mert');
// For JSON responses, resp.data contains the result
}, function(err) {
console.error('Selami');
console.error('ERR', err);
// err.status will contain the status code
})
});
}
我想将动态数据解析到应用程序但是进入控制台:
Error: [ng:areq] Argument 'MainCtrl' is not a function, got undefined.
我在这里缺少什么?如果我不写指令,则值为空白。