Skip to content

JasnaMRB/egghead-angular

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eggly Bookmarks

This app is to help me understand Angular 1 better. I am following Egghead.io's intro tutorial.

egghead.io

Style

I am not following the tutorial exactly. I'm instead trying to implement John Papa's style guide to get me used to that.

About

This app lets you add, edit, and delete Internet bookmarks.

Requirements

npm npm serve

To run

First time: npm install Then: http-server

Development Steps

Beginning

  1. Create HTML template
  2. Add Angular, jQuery, bootstrap dependencies
  3. Add ng-app to <html> opening tag to initialize Angular
  4. Create Angular app in app.js: angular.module('eggly',[])
  5. Create a main controller in main-controller.js: angular.module('eggly').controller('MainCtrl', MainCtrl); function MainCtrl() { var mainVm = this; mainVm.someVariable = null; mainVm.someFunction = someFunction; function someFunction() { ... } }
  6. Add your data, e.g., JSON for categories and bookmarks, in the controller.
  7. Register your controller with an element in the view: <body ng-controller="MainCtrl as mainVm">.
  8. In a child element, use ng-repeat and handlebars {{ }} <div><ul><li ng-repeat="bookmark in mainVm.bookmarks">{{ bookmark.title }}</li></ul></div>
  9. Create functions and variables to filter display of bookmarks by current selected category.
  10. Create functions and variables for CRUD operations on bookmarks.
  11. Create functions and variables to make display nicer, e.g., highlight active category or active bookmark.

Refactoring code for modularity/scalability

  1. Create a file structure based on feature .
  2. Create module angular.module('categories',[]) and submodule angular.module('categories.bookmarks', []) in their feature folders->JS files.
  3. Create submodules for create and edit bookmarks.
  4. Inject those submodules into the categories.bookmarks submodule: angular.module('categories.bookmarks', ['categories.bookmarks.create', 'categories.bookmarks.edit'])
  5. Create a common folder for things used across modules, e.g., models. Here we'll have bookmarks and categories models.
  6. Inject them in their appropriate features modules: angular.module('categories', ['eggly.models.categories']); and angular.module('categories.bookmarks', [ 'eggly.models.categories', 'eggly.models.bookmarks', 'categories.bookmarks.create', 'categories.bookmarks.edit' ]);
  7. Inject the bookmarks and categories modules into the main app module. angular.module("eggly", ['categories', 'categories.bookmarks']);
  8. Add ui-router for state URL and state parameters. State parameters help pass information between modules.
  9. Use ui-sref directive in view <a></a> tags so users can toggle between state URLs. In bookmarks controller: function bookmarkConfig($stateProvider) { $stateProvider.state('eggly.categories.bookmarks', { url: 'categories/:category', views: { 'bookmarks@': { templateUrl: 'webapp/categories/bookmarks/bookmarks.tmpl.html', controller: 'BookmarksCtrl as bmVm' } } }); } In categories view: <a ui-sref="eggly.categories.bookmarks({category:category.name})" ng-click="mainVm.setCurrentCategory(category)">{{ category.name }}</a>
  10. Create separate service classes to simplify controllers.
  11. Externalize inline data and call them with $http.get service.
  12. Use $q service which handles promises (what $http.get returns) for caching and other data manipulation before sending data to controllers.

About

Sample Angular 1 app

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages