Troubleshooting loading specific story types on hacker news API with Angular.js

I have been working on a hacker news client using the official hacker news firebase API and Angular.js. Everything seems to be working fine except for the 'jobstories' posts, which are not rendering on the screen even though the story IDs are being logged to the console. This is quite puzzling as the code works perfectly fine for 'topstories', 'maxitem', and 'showstories'. For those interested, here is the link to the Plunker.

angular.module('app.services', ['ngColorThis', 'ngTouch']).factory('HackerNews', function() {
return new Firebase('https://hacker-news.firebaseio.com/v0');});

angular.module('app.controllers', ['app.services']).controller('AppController', [
'$scope', '$sce', '$timeout', '$window', '$q', 'HackerNews', function($scope, $sce, $timeout, $window, $q, HackerNews) {
$scope.section = 'top';
$scope.gotoStory = function(story) {
  $scope.currentStory = story;
  $scope.storyUrl = $sce.trustAsResourceUrl(story.url);
  return $scope.navi.pushPage(cordova.ThemeableBrowser.open(story.url, '_blank', {toolbar: {
    height: 44,
    color: 'transparent'
}, closeButton: {
    image: 'ic_cancel_black',
    imagePressed: 'close_pressed',
    align: 'left',
    event: 'closePressed'
}}));
};
$scope.loadUrl = function(url) {
  return $window.open(url, '_blank', 'location=yes');
};
return $scope.getStory = function(id) {
  var deferred, timer;
  deferred = $q.defer();
  timer = $timeout(deferred.resolve, 1000);
  HackerNews.child("item/" + id).once('value', function(data) {
    var item;
    item = data.val();
    if (item && item.type === 'story' && !item.deleted && item.url) {
      $timeout.cancel(timer);
      return deferred.resolve(item);
    } else {
      $timeout.cancel(timer);
      return deferred.resolve();
    }
  });
  return deferred.promise;
};
}
]).controller('JobController', [
'$scope', '$q', 'HackerNews', function($scope, $q, HackerNews) {
$scope.stories = [];
$scope.getJobStories = function() {
  return HackerNews.child('jobstories').once('value', function(data) {
    var i, id, jobId, len, promises;
    console.log(data.val());
    jobId = data.val();
    promises = []; 
    for (i = 0, len = jobId.length; i < len; i++) {
      id = jobId[i];
      promises.push($scope.getStory(id));
    }
    return $q.all(promises).then(function(stories) {
      stories = stories.filter(function(story) {
        return typeof story !== 'undefined';
      });
      if (stories.length > 0) {
        return $scope.stories = stories;
      }
    });
  });
};
return HackerNews.child('jobstories').on('value',   $scope.getJobStories);
}
]);

      <ons-template id="jobs.html">
        <ons-navigator var="navi">
            <ons-list  ng-controller="JobController">            
              <ons-list-item  modifier="tappable" ng-repeat="story in stories" ng-click="gotoStory(story); showme=true;">   
                <div ng-hide="showme">  
                  <div style="padding: 0 10px 0 10px;">   
                    <span color-this="color" data-color="story.title" class="story-title">{{ story.title }}</span>           
                    <span color-this="color" data-color="story" class="story-site">({{ story.url | urlToHost }})</span>            
                    <span style="display:inline" class="story-info">{{ story.score }} points by</span><span style="display:inline" color-this="color" data-color="story.title" class="story-info"> {{ story.by }} </span><span style="display:inline" class="story-info">{{ story.time | timeAgo }}</span>           
                  </div>           
                </div>           
                <div ng-show="showme" style="opacity:0.4" color-this="background" data-color="story.title">                      
                  <div style="padding: 0 10px 0 10px;">            
                    <span class="story-title">{{ story.title }}</span>             
                    <span color-this="color" data-color="story" class="story-site">({{ story.url | urlToHost }})</span>              
                    <span class="story-info">{{ story.score }} points by {{ story.by }} {{ story.time | timeAgo }}</span>            
                  </div>
                </div>
              </ons-list-item>
           </ons-navigator>
         </ons-template>

Answer №1

After some investigation, I've identified the issue. There was a line of code

if (item && item.type === 'story' && !item. DELETED&& item.url)
that was filtering out items of type "story." However, job posts have a type of "job", so they were not being displayed. By removing the type condition, I was able to successfully show the job posts on the screen.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Launching the webpage with Next.js version 13

Hey there! I'm currently working on implementing a loading screen for my website to enhance the user experience. Since it's quite a large site, I believe a loading screen would be beneficial. However, I'm having trouble getting it to work on ...

Difficulty encountered while managing dropdown functionality in Protractor using TypeScript

I'm encountering some difficulties when it comes to selecting a dropdown in Protractor. Here's the structure of my DOM: https://i.stack.imgur.com/qK8sT.png This is the XPath I'm using to select the dropdown with the value "Yes": //label[ ...

Generating a dynamic method for uploading multiple files

Is there a way to dynamically generate multiple upload forms upon clicking a button? I currently have code that allows for uploading one file, but I would like to be able to add additional forms for each file. In other words, if I need to upload 7 files, I ...

Combining the power of AngularJS with the versatility of sails

A project I'm working on involves utilizing sails.js for back-end and AngularJS for front-end. My plan is to use the Yeoman-angular generator https://github.com/yeoman/generator-angular to create the Angular app first. Once the front-end development i ...

When attempting to run JavaScript within PHP, an Uncaught SyntaxError is encountered

When I run this code without PHP, it works perfectly. <?php $activeStatus = "$getuser[active]"; if($activeStatus == 1) { echo '<script type="text/javascript">'; echo ' $(document).ready(function () { v ...

Fade in and out on button press

There is a button with the following HTML code: <input type="submit" id="btnApply" name="btnApply" value="Apply"/> Upon clicking the button, a div should be displayed. <div> Thanks for applying </div> The display of the div should fade ...

Dynamic Form Layout with Angulajs' Adaptive Data

As a developer, I have created a form using a directive and I am supplying the layout data from my controller. TheController.js [{ "type":"selectbox", "name":"name_one", "label":"Name One" }] This information is then sent to my form_directive which handl ...

Tips for making a hide and reveal FAQ section

Currently working on creating a FAQ page for my website, I ran into a challenge. My goal is to have a setup where clicking on a question will reveal the answer while hiding any previously open answers. So far, I have managed to achieve this functionality p ...

Change to JSONArray using angularjs

Here is a json object: "values": [ {"name": "name1"}, {"name": "name2"}, {"name": "name3"} ] I want to convert it into this format: values: ["name1", "name2", "name3"]; Can this conversion be done in AngularJS or any other JavaScript functi ...

Utilizing jQuery to compute dynamic fields depending on selection in a dropdown menu

Creating a Ruby app for tracking bets, I have designed a small form that captures various details including date and match. However, the most crucial components of this form are the "stake" and "odd" text fields. To enhance user experience, I have incorpor ...

"Step-by-step guide: Implementing a fixed scroll sidebar in AngularJS to mimic Facebook's sidebar (

As a newcomer to AngularJS, I've encountered challenges and invested a considerable amount of time trying to create a fixed right side directory. Here are the key features of the fixed scroll directory: 1) If the sidebar (whether on the Right or Left ...

Clicking on React Js reverses an array that had previously been unreversed

My issue involves an array pulled from a database that I have reversed so that the newest entry is displayed at the top when a button is clicked, opening a modal-style window. However, when the array is displayed in the modal window, it appears to be flipp ...

The Ajax operation does not finish before the second one is initiated

My Ajax function is set up like this: function PersonAtlLawUpdate(personRef) { var selectionPanel = $('div#SelectionPanel'); var fromdate = selectionPanel.find('input#FromDateTextBox')[0].defaultValue; var timeSpan = selectionPanel.fin ...

Tips for Removing Padding in Material UI Container Component

I'm currently working on creating a hero banner using the material-ui framework and I've encountered an issue. Here's what I have so far: https://i.stack.imgur.com/UXTDY.png However, I'm facing an irritating problem with left and rig ...

Error encountered while attempting to install ungit on Windows XP: Unable to locate file directory in C:/Documents

Ungit seems like the ideal tool to gain a better understanding of git, thanks to its graphical interface that simplifies the process. I came across this video explanation which is very helpful in grasping how git functions, even if you don't intend to ...

What is the process of converting an image taken with the 'react-camera-pro' into a byte array?

I am in the process of capturing an image using a camera through 'react-camera-pro' and I need to figure out how to convert the captured image into a byte array. Here is the snippet of code that I am working with: const camera = useRef(null); ...

Why is my Typescript event preventDefault function ineffective?

Despite all my efforts, I am still unable to prevent the following a tag from refreshing the page every time it's clicked. <p> <a onClick={(e) => handleClick} href="&qu ...

Utilizing jQuery to gather the values of all checkboxes within each group and dynamically adding them to a span element for counting purposes

I am currently working on a project that involves sets of groups with checkboxes. My goal is to retrieve the value of each checkbox when checked and add this value to a counter span element located beside it. However, I have encountered an issue where clic ...

If the div element undergoes a change, use an if-else condition to populate the data fields accordingly

I'm looking to create a basic if/else statement in JavaScript that checks if a div element has changed before populating JSON data fields/variables that pull from dynamically updated HTML. I want to avoid using the deprecated DOMSubtreeModified metho ...

Stop fullscreen mode in Angular after initiating in fullscreen mode

Issue with exiting full screen on Angular when starting Chrome in full-screen mode. HTML: <hello name="{{ name }}"></hello> <a href="https://angular-go-full-screen-f11-key.stackblitz.io" target="_blank" style=& ...