Home Ionic Framework Interaction with API
Reply: 0

Ionic Framework Interaction with API

user1283 Published in July 16, 2018, 6:28 am

I'm trying to retrieve information from Reddit's JSON API(RedditUrl.json) and show it on my Ionic Creator App. I've bound the HTML and JS by typing {{variable}}, so that's not the problem. In addition to that, I typed Angular Directives on the component I'm working with like:

ng-app = "ionicApp" ng-controller = "MainCtrl"

Actual JS code:

function ($scope, $stateParams) {


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;
        // For JSON responses, resp.data contains the result
    }, function(err) {
        console.error('ERR', err);
        // err.status will contain the status code


I want to parse dynamic data to the app but am getting in the console:

Error: [ng:areq] Argument 'MainCtrl' is not a function, got undefined.

What am I missing here? If I don't write the directives, values are being blank.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.359468 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO