Git Product home page Git Product logo

angular-hacker-news-lab-v-000's Introduction

Recreating HackerNews in Angular

Objectives

  • Use the HackerNews API to create a clone app
  • Render the top stories view
  • Use ui-router for advanced routing
  • Use dynamic views in routes
  • Set the top stories view as the default route
  • Create relevant Controllers and Services
  • Use relevant Directives to bind ViewModels and Events
  • Use routing resolves to preload data fetched from Services
  • Allow a user to transition to a news item when clicked
  • Show all comments for a post in the news item
  • Nest replies to comments where necessary
  • Display dates in human-readible formats
  • Allow the user to navigate "Next" and "Previous" page

Instructions

To run the local dev server, you'll need to run npm install and then node server.js. This will run a local dev server at http://localhost:8080.

HackerNews is a basic news site where people can post items and comment on them. Let's recreate some of it. Take a look at it here.

Create a state for the "top stories".

We should then grab all the top stories from the URL https://hacker-news.firebaseio.com/v0/topstories.json. If you go to that URL, you'll see we actually get lots of IDs - around 500 or so.

Create a service, and a method to grab all the top stories. Then create a method to grab information about a single post by it's ID. This should hit https://hacker-news.firebaseio.com/v0/item/{id}.json.

Display a list of 30 posts on the top stories, and put two links at the bottom to allow the user to change to the next/previous page. As we've already got the ~500 or so top stories, we can just slice a different chunk out of the array depending what page they're on instead of making a new request.

Note normally with pagination, we'd request a new dataset from the server depending what page number we're on. However, in this case, we'll already have all of the top stories, so we'll just need to slice a different part of the array.

Each top story should have it's URL displayed along with the amount of comments and the score.

Create another route to view a post with a given ID. This should make a request to the same URL above. Then, display the same information that we displayed for each item (URL, comments, score).

Each post has an array of kids. This is a list of comments inside the post. These again, are items, so to retrieve the info for the comment, we hit the same URL - https://hacker-news.firebaseio.com/v0/item/{id}.json. We can tell stories and comments apart by the type property.

Create a component to display the comments - this should grab data from the URL on initialisation. The comments contents are provided to use in HTML, however Angular doesn't allow us to inject HTML into our templates from a variable. Use the ngSanitize module to allow us to do this (hint: we need to use ng-bind-html).

Each kid (comment) might have kids (comments) inside it - so each comment should actually call the comment component inside of it. This means we've got a recursive component - awesome!

There are simple styles for you to use inside app.css to make it look pretty!

Resources

angular-hacker-news-lab-v-000's People

Contributors

toddmotto avatar ipc103 avatar mystycs avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.