CustomDirectives-Lecture26/customDirectives-without Isolation scope/app.js
// If not specified, maxItems assumed unlimited
If not specified, maxItems assumed unlimited
If not specified maxItems assumed unlimited
function ShoppingListService(maxItems) {
  var service = this;
  var items = [];
  service.addItem = function (itemName, quantity) {
    if ((maxItems === undefined) ||
        (maxItems !== undefined) && (items.length < maxItems)) {
      var item = {
        name: itemName,
        quantity: quantity
      };
      items.push(item);
    }
    else {
      throw new Error("Max items (" + maxItems + ") reached.");
    }
  };
  service.removeItem = function (itemIndex) {
    items.splice(itemIndex, 1);
  };
  service.getItems = function () {
    return items;
  };
}
function ShoppingListService ( maxItems ) { var service = this ; var items = [ ] ; service . addItem = function ( itemName , quantity ) { if ( ( maxItems === undefined ) || ( maxItems !== undefined ) && ( items . length < maxItems ) ) { var item = { name : itemName , quantity : quantity } ; items . push ( item ) ; } else { throw new Error ( "Max items (" + maxItems + ") reached." ) ; } } ; service . removeItem = function ( itemIndex ) { items . splice ( itemIndex , 1 ) ; } ; service . getItems = function ( ) { return items ; } ; }
If not specified, maxItems assumed unlimited
If not specified maxItems assumed unlimited
// List of shopping items