Creating A Single View Application Using Ionic

Ionic Single View Project

In this article, we will create a "Single View" application, and we will show the list of stories with title and time; and after clicking on any story, it will redirect to the complete story. For the raw data, we will consider the “Reddit” website because we can retrieve data from Reddit without any prior authentication. 

We will consider the following topics.

  • Create Single View
  • List of Items
  • Infinite Scroll
  • Pull to refresh
  • Thumbnail, title and details of stories
  • Create AngularJS Controller
  • Load JSON data using $http service
  • Add Cordova Plugin
  • Add JavaScript Library: Moment.js
  • Add Side Menu for NEWS categories
  • Add Tab for NEWS type.

Before start working on the application, let’s first visit Reddit.

Reddit is a social stories aggregation, web content rating, and discussion website. Reddit's registered community members can submit content, such as text posts or direct links. Wikipedia.



You can select any subreddits, such as games, IOS, Hindi, or pics.

Funny Subreddit



To get data for any subreddit, just append the “.json” at the end of URL. It will return the data for subreddit in JSON format.



Now, we can use the data for our application. Let’s start working on this project. First of all, create a blank layout application and name it “redditApp”.



After installation,  open the project in any IDE; I am using Visual Studio. After opening the project in any IDE click on the Index.html page. This is the first and most important page of the project.



First of all change header title from “Ionic Blank Starter” to “Reddit App”.

Create controller and get data from Reddit API.

Now we create a controller and using the “$http” service we retrieve the data from Reddit Api.



Controller

  1. var appMod = angular.module('starter', ['ionic']);  
  2. appMod.controller('redditCtrl'function ($scope,$http) {  
  3.     $scope.STORIESContent = [];  
  4.     $http({  
  5.         method: 'GET',  
  6.         url: 'https://www.reddit.com/.json'  
  7.     }).then(function successCallback(response) {  
  8.         console.log(response);  
  9.     }, function errorCallback(response) {  
  10.         console.log(response);  
  11.     });  
  12.   
  13. });  
Output



In the above screen, we called the $http service and retrieved the data from Reddit in JSON format, this data contains all required information like URl, Author Name, thumbnail, and title. Now, we will show this data in View.

Controller
  1. var appMod = angular.module('starter', ['ionic']);  
  2. appMod.controller('redditCtrl'function ($scope,$http) {  
  3.     $scope.STORIESContent = [];  
  4.     $http({  
  5.         method: 'GET',  
  6.         url: 'https://www.reddit.com/.json'  
  7.     }).then(function successCallback(response) {  
  8.         angular.forEach(response.data.data.children, function (child) {  
  9.             $scope.STORIESContent.push(child.data);  
  10.         });  
  11.          
  12.     }, function errorCallback(response) {  
  13.         console.log(response);  
  14.     });  
  15.   
  16. });  
View(Index.html)
  1. <body ng-app="starter" ng-controller="redditCtrl">  
  2.   
  3.     <ion-pane>  
  4.       <ion-header-bar class="bar-stable">  
  5.         <h1 class="title">Reddit App</h1>  
  6.       </ion-header-bar>  
  7.       <ion-content>  
  8.           <div ng-repeat="data in STORIESContent">  
  9.               <a ng-href="{{data.url}}" target="_blank">{{data.title}}</a>  
  10.               ({{data.domain}})  
  11.               <span>{{data.num_comments}} Comments</span>  
  12.               <span>Submitted By: {{data.author}} </span>  
  13.               <span>Score: {{data.score}} </span>  
  14.           </div>  
  15.       </ion-content>  
  16.     </ion-pane>  
  17.   </body>  
Output



In the above code, we retrieve the data from Reddit API and show the title, author name, URL, comments, and score of the stories. Now, we add some CSS components to improve the look of our app.

First of all, we add a header. To change the style of header, we add the “bar-balanced” class for the header.

We will use the below style of the list.



We modify our previous code to get the above look for the application.

Code
  1. <body ng-app="starter" ng-controller="redditCtrl">  
  2.   
  3.   <ion-pane>  
  4.     <ion-header-bar class="bar-balanced">   
  5.       <h1 class="title">Reddit App</h1>  
  6.     </ion-header-bar>  
  7.     <ion-content>  
  8.         <div ng-repeat="data in STORIESContent" class="list" style="margin-bottom: 2px;">  
  9.             <a class="item item-thumbnail-left item-text-wrap" ng-href="{{data.url}}" target="_blank"  >  
  10.                  
  11.                 <img src="{{data.thumbnail}}" ng-if="data.thumbnail.startsWith('http')"/>  
  12.                 <p>  <h2 class="positive story-title">{{data.title}}</h2>-({{data.domain}})</p>  
  13.   
  14.                 <p>Submitted By: {{data.author}} </p>  
  15.   
  16.                 <p>{{data.num_comments}} Comments;  Score: {{data.score}}</p>  
  17.                  
  18.             </a>  
  19.               
  20.         </div>  
  21.     </ion-content>  
  22.   </ion-pane>  
  23. </body>  
After using the above code now our application will look like below.



Add JavaScript Library

Now, we want to show how long ago the story was published, for this we can use created_utc property that will show the time in seconds.





You can see that it represents the number of seconds since Jan 1 1970, now we want to show this time similar to  how the Reddit web site does it.



There are two methods to do this. The first one is that we create a custom code that will convert these seconds into a proper time format that we want or we can use any pre-built JavaScript library. I think the second method is best. So now we will learn how to install a JavaScript library in our project. For our application we us the “monment.js” library. For this go to the “Momentjs.com” website.



This JavaScript library is used to convert a time count into a proper time format.



GitHub also provides Moment.JS directive for Angular.JS, that will be easy for us to use in out application. Now we go to GitHub and download the required files for Moment.JS directives.





After successful installation add the below code into the index.html page.
  1. <script src="lib/moment/moment.js"></script>  
  2. <script src="lib/angular-moment/angular-moment.js"></script>  
Add “angularMoment” dependency in Module.



Add the below code in Index.html page.

Now time will appear in  the below format.



Adding Infinite Scroll

Now we are getting only 25 stories at a time, but what if we want to see the older stories? So now we add an infinite scroll; using that we can read the older stories Let’s read the documentation of Reddit API.



If you read the API documentation of Reddit then you will find that we can load after or before stories by specifying the name of stories. Let’s check this statement.



Load new stories published after this story. To get new stories you can use pass before the parameter and to get the old stories you can use pass after the parameter value. Here we pass https://www.reddit.com/.json?before=t3_5afcrc that will return new stories published after stories with the name “t3_5afcrc”. We pass the “after” parameter value in our application to get the older stories.



Use Ionic Infinite Scroll API

Now we use the Ionic infinite scroll API, you can get more information about Ionic infinite scroll here. Now we add the required components in Html page and controller section as defined in documentation.



Html Code
  1. <body ng-app="starter" ng-controller="redditCtrl">  
  2.   
  3.     <ion-pane>  
  4.       <ion-header-bar class="bar-balanced">   
  5.         <h1 class="title">Reddit App</h1>  
  6.       </ion-header-bar>  
  7.       <ion-content>  
  8.           <div ng-repeat="data in NEWSContent track by data.id" class="list" style="margin-bottom: 2px;">  
  9.               <a class="item item-thumbnail-left item-text-wrap" ng-href="{{data.url}}" target="_blank"  >  
  10.                    
  11.                   <img src="{{data.thumbnail}}" ng-if="data.thumbnail.startsWith('http')"/>  
  12.                   <p>  <h2 class="positive story-title">{{data.title}}</h2>-({{data.domain}})</p>  
  13.   
  14.                   <p>Submitted <span am-time-ago="data.created_utc| amFromUnix"  
  15.                                       am-preprocess="unix"></span>  by: {{data.author}} </p>  
  16.   
  17.                   <p>{{data.num_comments}} Comments;  Score: {{data.score}}</p>  
  18.                    
  19.               </a>  
  20.                 
  21.           </div>  
  22.           <ion-infinite-scroll on-infinite="loadMore()"  
  23.                                distance="1%">  
  24.           </ion-infinite-scroll>  
  25.       </ion-content>  
  26.     </ion-pane>  
  27.   </body>  
Controller
  1. var appMod = angular.module('starter', ['ionic''angularMoment']);  
  2. appMod.controller('redditCtrl'function ($scope,$http) {  
  3.     $scope.NEWSContent = [];  
  4.     $scope.loadMore = function () {  
  5.         var param = {};  
  6.         if ($scope.NEWSContent.length > 0) {  
  7.             param['after'] = $scope.NEWSContent[$scope.NEWSContent.length - 1].name;  
  8.         }  
  9.         $http({  
  10.             method: 'GET',  
  11.             url: ' https://www.reddit.com/r/all/',  
  12.             params:param  
  13.         }).then(function successCallback(response) {  
  14.             angular.forEach(response.data.data.children, function (child) {  
  15.                 $scope.NEWSContent.push(child.data);  
  16.             });  
  17.             $scope.$broadcast('scroll.infiniteScrollComplete');  
  18.         }, function errorCallback(response) {  
  19.             console.log(response);  
  20.         });  
  21.     };  
  22.       
  23.   
  24. });  
Above html and JavaScript code provide a functionality of infinite scroll, when you reach the bottom of the page it will fetch 25 stories that were  published before the last story.



Add Ionic Refresher

Now we add a refresher in our app, using this refresher we will get new stories. For more information about the refresher read the documentation of Ionic refresher.



Now we add <ion-referesher> element in our code.

Html
  1. <body ng-app="starter" ng-controller="redditCtrl">  
  2.   
  3.     <ion-pane>  
  4.       <ion-header-bar class="bar-balanced">   
  5.         <h1 class="title">Reddit App</h1>  
  6.       </ion-header-bar>  
  7.       <ion-content>  
  8.           <ion-refresher pulling-text="Pull to refresh..."  
  9.                          on-refresh="doRefresh()">  
  10.           </ion-refresher>  
  11.           <div ng-repeat="data in NEWSContent track by data.id" class="list" style="margin-bottom: 2px;">  
  12.               <a class="item item-thumbnail-left item-text-wrap" ng-href="{{data.url}}" target="_blank"  >  
  13.                    
  14.                   <img src="{{data.thumbnail}}" ng-if="data.thumbnail.startsWith('http')"/>  
  15.                   <p>  <h2 class="positive story-title">{{data.title}}</h2>-({{data.domain}})</p>  
  16.   
  17.                   <p>Submitted <span am-time-ago="data.created_utc| amFromUnix"  
  18.                                       am-preprocess="unix"></span>  by: {{data.author}} </p>  
  19.   
  20.                   <p>{{data.num_comments}} Comments;  Score: {{data.score}}</p>  
  21.                    
  22.               </a>  
  23.                 
  24.           </div>  
  25.           <ion-infinite-scroll on-infinite="loadMore()"  
  26.                                distance="1%">  
  27.           </ion-infinite-scroll>  
  28.       </ion-content>  
  29.     </ion-pane>  
  30.   </body>  
Controller
  1. $scope.NEWSContent = [];  
  2.     $scope.doRefresh = function () {  
  3.         var param = {};  
  4.         param['before'] = $scope.NEWSContent[0].name;  
  5.         var oldStory = [];  
  6.         oldStory = $scope.NEWSContent;  
  7.         var newStory = [];  
  8.         $http({  
  9.             method: 'GET',  
  10.             url: 'https://www.reddit.com/.json',  
  11.             params: param  
  12.         }).then(function successCallback(response) {  
  13.             angular.forEach(response.data.data.children, function (child) {  
  14.                 newStory.push(child.data);  
  15.             });  
  16.             $scope.NEWSContent = [];  
  17.             angular.forEach(newStory, function (data) {  
  18.                 $scope.NEWSContent.push(data);  
  19.             });  
  20.             angular.forEach(oldStory, function (data) {  
  21.                 $scope.NEWSContent.push(data);  
  22.             });  
  23.   
  24.             $scope.$broadcast('scroll.refreshComplete');  
  25.         }, function errorCallback(response) {  
  26.             console.log(response);  
  27.         });  
  28.     };  
After adding the above code if we refresh(Pull Down) the screen then it will send a request to the Reddit API for the latest stories and show you on the screen.



In the above image we pull down the screen to get the latest stories, in the  result form we get two new stories showing on the top.



So far our application is working properly but if we click on any story then it will open the story in a new tab. It can work in a general web browser but when we build this application for Android or IOS then it will cause an error because Android and IOS use the WebView that is a kind of browser for mobile but it refused to open any external link. To resolve this issue we use the “inappbrowser” Cordova plugin.



Run “Ionic plugin add cordova-plugin-inappbrowser” command to add the “inappbrowser” plugin.



After adding the Plugin now we make a change in index.html and app.js .

In index.html remove href from anchor tag and add the ng-click directive as below.



App.js

Add openPage function in App.js



And make some modification in run method


In the above code we changed the window.open for a mobile device, when we run this app in a mobile device it will open a link in “InAppBrowser” and in case of regular web browser it will not insert in “if” section and open the link in a new tab.

Let’s build the application and check if all these modifications work or not.



When we click on any link it will open that story in InAppBrowser.



Add Side Menu
 
So far we are getting stories only for “ALL” category, how much better would it be if we could get stories for other categories like Funny, Pics etc. Now we add side menu in our application and insert categories in this menu like below.





To use side menus add <ion-side-menus> that will encompass all pages that have a side menu, <ion-side-menu-content> for the center content, and one or more <ion-side-menu> directives for each side menu(left/right) that you wish to place. For side menu element add your element in <ion-side-menu> like below.



Html Code
  1. <body ng-app="starter" ng-controller="redditCtrl">  
  2. <ion-side-menus>  
  3.     <ion-side-menu-content>  
  4.           
  5.         <ion-nav-bar class="bar-stable">  
  6.             <ion-nav-buttons side="left">  
  7.                 <button menu-toggle="left" class="button button-icon button-clear ion-navicon ">  
  8.                        
  9.                 </button>  
  10.                 <div class="title title-center header-item" >{{title}}</div>  
  11.             </ion-nav-buttons>  
  12.               
  13.         </ion-nav-bar>  
  14.         <ion-pane>  
  15.             <ion-header-bar class="bar-balanced">  
  16.                 
  17.             </ion-header-bar>  
  18.             <ion-content>  
  19.                 <ion-refresher pulling-text="Pull to refresh..."  
  20.                                on-refresh="doRefresh()">  
  21.                 </ion-refresher>  
  22.                 <div ng-repeat="data in NEWSContent track by data.id" class="list" style="margin-bottom: 2px;">  
  23.                     <a class="item item-thumbnail-left item-text-wrap" ng-click="openPage(data.url)">  
  24.   
  25.                         <img src="{{data.thumbnail}}" ng-if="data.thumbnail.startsWith('http')" />  
  26.                         <p>  <h2 class="positive story-title">{{data.title}}</h2>-({{data.domain}})</p>  
  27.   
  28.                         <p>  
  29.                             Submitted <span am-time-ago="data.created_utc| amFromUnix"  
  30.                                             am-preprocess="unix"></span>  by: {{data.author}}  
  31.                         </p>  
  32.   
  33.                         <p>{{data.num_comments}} Comments;  Score: {{data.score}}</p>  
  34.   
  35.                     </a>  
  36.   
  37.                 </div>  
  38.                 <ion-infinite-scroll on-infinite="loadMore()"  
  39.                                      distance="1%">  
  40.                 </ion-infinite-scroll>  
  41.             </ion-content>  
  42.         </ion-pane>  
  43.     </ion-side-menu-content>  
  44.     <ion-side-menu side="left">  
  45.         <ion-content>  
  46.             <div class="list">  
  47.                 <a class="item item-icon-left" ng-click="Load_SubReddits('https://www.reddit.com/r/all/.json')">  
  48.                     <i class="icon ion-clipboard"></i>ALL</a>  
  49.                 <a class="item item-icon-left" ng-click="Load_SubReddits('https://www.reddit.com/r/funny/.json')">  
  50.                     <i class="icon ion-social-foursquare-outline"></i>FUNNY</a>  
  51.                 <a class="item item-icon-left" ng-click="Load_SubReddits('https://www.reddit.com/r/pics/.json')">  
  52.                     <i class="icon ion-images"></i>PICS</a>  
  53.                 <a class="item item-icon-left" ng-click="Load_SubReddits('https://www.reddit.com/r/angularjs/.json')">  
  54.                     <i class="icon ion-social-angular-outline"></i>Angularjs</a>  
  55.                 <a class="item item-icon-left" ng-click="Load_SubReddits('https://www.reddit.com/r/node/.json')">  
  56.                     <i class="icon ion-social-nodejs"></i>NodeJ </a>  
  57.                 <a class="item item-icon-left" ng-click="Load_SubReddits('https://www.reddit.com/r/blog/.json')">  
  58.                     <i class="icon ion-ios-compose"></i>BLOG</a>  
  59.                 <a class="item item-icon-left" ng-click="Load_SubReddits('https://www.reddit.com/r/books/.json')">  
  60.                     <i class="icon ion-ios-book-outline"></i>BOOKS</a>  
  61.                 <a class="item item-icon-left" ng-click="Load_SubReddits('https://www.reddit.com/r/food/.json')">  
  62.                     <i class="icon ion-fork"></i>FOOD</a>  
  63.             </div>  
  64.         </ion-content>  
  65.     </ion-side-menu>  
  66. </ion-side-menus>  
  67.      
  68.   </body>  
After all these changes now we need to make changes in controller; replace controller code with below code.
  1. appMod.controller('redditCtrl'function ($scope, $http) {  
  2.     $scope.title="ALL";  
  3.     $scope.NEWSContent = [];  
  4.     $scope.Load_SubReddits = function (url_) {  
  5.         $scope.NEWSContent = [];  
  6.         $scope.title = url_.split('/')[4].toUpperCase();  
  7.         $http({  
  8.             method: 'GET',  
  9.             url: url_  
  10.         }).then(function successCallback(response) {  
  11.   
  12.             angular.forEach(response.data.data.children, function (child) {  
  13.                 if (!child.data.thumbnail|| child.data.thumbnail === 'self' || child.data.thumbnail === 'default') {  
  14.                     child.data.thumbnail = 'http://www.redditstatic.com/icon.png';  
  15.                 }  
  16.                 $scope.NEWSContent.push(child.data);  
  17.             });  
  18.             $scope.$broadcast('scroll.infiniteScrollComplete');  
  19.         }, function errorCallback(response) {  
  20.   
  21.             console.log(response);  
  22.             $scope.$broadcast('scroll.infiniteScrollComplete');  
  23.         });  
  24.     };  
  25.     $scope.openPage = function (url) {  
  26.         window.open(url, '_blank');  
  27.     }  
  28.     $scope.doRefresh = function () {  
  29.         var param = {};  
  30.         param['before'] = $scope.NEWSContent[0].name;  
  31.         var oldStory = [];  
  32.         oldStory = $scope.NEWSContent;  
  33.         var newStory = [];  
  34.         $http({  
  35.             method: 'GET',  
  36.             url: 'https://www.reddit.com/r/' + $scope.title + '/.json',  
  37.             params: param  
  38.         }).then(function successCallback(response) {  
  39.             angular.forEach(response.data.data.children, function (child) {  
  40.                 newStory.push(child.data);  
  41.             });  
  42.             $scope.NEWSContent = [];  
  43.             angular.forEach(newStory, function (data) {  
  44.                 $scope.NEWSContent.push(data);  
  45.             });  
  46.             angular.forEach(oldStory, function (data) {  
  47.                 $scope.NEWSContent.push(data);  
  48.             });  
  49.   
  50.             $scope.$broadcast('scroll.refreshComplete');  
  51.         }, function errorCallback(response) {  
  52.             console.log(response);  
  53.         });  
  54.     };  
  55.     $scope.loadMore = function () {  
  56.         var param = {};  
  57.         if ($scope.NEWSContent.length > 0) {  
  58.             param['after'] = $scope.NEWSContent[$scope.NEWSContent.length - 1].name;  
  59.         }  
  60.          
  61.         $http({  
  62.             method: 'GET',  
  63.             url: 'https://www.reddit.com/r/' + $scope.title + '/.json',  
  64.             params:param  
  65.         }).then(function successCallback(response) {  
  66.              
  67.             angular.forEach(response.data.data.children, function (child) {  
  68.                 if (child.data.thumbnail === 'self' || child.data.thumbnail === 'default') {  
  69.                     child.data.thumbnail = 'http://www.redditstatic.com/icon.png';  
  70.                 }  
  71.                 $scope.NEWSContent.push(child.data);  
  72.             });  
  73.             $scope.$broadcast('scroll.infiniteScrollComplete');  
  74.         }, function errorCallback(response) {  
  75.   
  76.             console.log(response);  
  77.             $scope.$broadcast('scroll.infiniteScrollComplete');  
  78.         });  
  79.     };  
  80.       
  81.   
  82. });  
In this code we add Load_SubReddits function , in this function we have a Url_ parameter that contains the URL of the category. Using this parameter value we get the data from Reddit.









According to  the selected menu items stories will be fetched and content of the lists will be changed.

Add Tab for sub categories

If you go to Reddit 's official website then you will see that NEWS related to a single category is also divided into further sub categories like hot, new, rising, top etc.



Now we add a tab into our app and use this tab to get the NEWS for subcategories. We add only four items (HOT, TOP, NEW, RISING) into our tab section.

You can read Ionic tab documentation for more details about the Ionic tab.



Now add four variables in your controller for the subcategory.
  1. $scope.hotURL = '';  
  2. $scope.topURL = '';  
  3. $scope.newURL = '';  
  4. $scope.risingURL = '';  
After making the above changes now Update the Load_SubReddits method as below.
  1. $scope.Load_SubReddits = function (url_) {  
  2.         $scope.NEWSContent = [];  
  3.         $scope.title = url_.split('/')[4].toUpperCase();  
  4.         $http({  
  5.             method: 'GET',  
  6.             url: url_  
  7.         }).then(function successCallback(response) {  
  8.   
  9.             angular.forEach(response.data.data.children, function (child) {  
  10.                 if (!child.data.thumbnail|| child.data.thumbnail === 'self' || child.data.thumbnail === 'default') {  
  11.                     child.data.thumbnail = 'http://www.redditstatic.com/icon.png';  
  12.                 }  
  13.                 $scope.NEWSContent.push(child.data);  
  14.             });  
  15.             $scope.$broadcast('scroll.infiniteScrollComplete');  
  16.             $scope.hotURL = 'https://www.reddit.com/r/' + $scope.title + '/hot/.json';  
  17.             $scope.topURL = 'https://www.reddit.com/r/' + $scope.title + '/top/.json';  
  18.             $scope.newURL = 'https://www.reddit.com/r/' + $scope.title + '/new/.json';  
  19.             $scope.risingURL = 'https://www.reddit.com/r/' + $scope.title + '/rising/.json';  
  20.         }, function errorCallback(response) {  
  21.   
  22.             console.log(response);  
  23.             $scope.$broadcast('scroll.infiniteScrollComplete');  
  24.         });  
  25.     };  
In the above code we are generating the URL for the sub categories as any main category will be changed; then values of subcategories also change.

Index.html

Add below code in your index.html page below the “ion-nav-button”.
  1. <div class="tabs tabs-icon-top">  
  2.   <a class="tab-item" ng-click="category(hotURL)">  
  3.     <i class="icon ion-contrast"></i>  
  4.     HOT  
  5.   </a>  
  6.   <a class="tab-item" ng-click="category(topURL)">  
  7.     <i class="icon ion-star"></i>  
  8.     TOP  
  9.   </a>  
  10.   <a class="tab-item" ng-click="category(newURL)">  
  11.     <i class="icon ion-ios-flame-outline"></i>  
  12.     NEW  
  13.   </a>  
  14.                <a class="tab-item" ng-click="category(risingURL)">  
  15.                    <i class="icon ion-ios-speedometer-outline"></i>  
  16.                    RISING  
  17.                </a>  
  18. </div>  


After making the above changes now our app will look like below.





Now you can see that in our application’s tab we have four buttons. These buttons work as sub categories of a main category. For each subcategory we added a category function on click event and in this function we are passing the absolute url of the NEWS topics. For example when we click on “Top” subcategory for AngularJS then the URL will be https://www.reddit.com/r/angularJS/hot/.json.

Now we add the category function in our js file and the code of the category function is below.
  1. $scope.category = function (url_) {  
  2.         $http({  
  3.             method: 'GET',  
  4.             url: url_  
  5.         }).then(function successCallback(response) {  
  6.             $scope.NEWSContent = [];  
  7.             angular.forEach(response.data.data.children, function (child) {  
  8.                 if (!child.data.thumbnail || child.data.thumbnail === 'self' || child.data.thumbnail === 'default') {  
  9.                     child.data.thumbnail = 'http://www.redditstatic.com/icon.png';  
  10.                 }  
  11.                 $scope.NEWSContent.push(child.data);  
  12.             });  
  13.               
  14.         }, function errorCallback(response) {  
  15.   
  16.             console.log(response);  
  17.              
  18.         });  
  19.     }  
In this example, we are getting the content for subcategory of any topic and showing it in the list. Congrats! this is the last step to complete this application.

Conclusion

In this article, first of all we created a single view, and after that we fetched out the data from Reddit API and showed in a list. In the next step we added an infinite scroll that allowed us to load infinite data. In further steps we added a refresh button, and using this button we can refresh our application screen and load the latest NEWS. We also added a side menu and in this side menu we inserted some categories of news and at last we added a tab and in this tab we added four sub-categories for a main-category.

I hope you liked this article. If you have any doubt or questions, then write in comment sections. Thanks for reading the article.

 


Similar Articles