Home Ionic Framework Interaction with API
Reply: 0

Ionic Framework Interaction with API

HalilM
1#
HalilM Published in 2017-12-07 16:48:48Z

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) {

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

}

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.322951 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO