Hi Sander,

i work on the ngCartItem Factory to convert them to typescript

import { Injectable } from '@angular/core';
import {Item} from '../ngcart/item.model'

@Injectable()
export class ItemService {
public _id;
public _articleId;
public _name;
public _price ;
public _quantity;
public _packagingUnit;
public _scaledPrice;
public _imagePath;
private item: {}; 
 
  constructor() {
  
   }

public setItem(id, articleId, name, price, quantity, packagingUnit, 
scaledPrice, imagePath){
this.setId(id);
this.setarticleId(articleId);
this.setName(name);
this.setPrice(price);
this.setQuantity(quantity, false);
this.setPackagingUnit(packagingUnit);
this.setScaledPrice(scaledPrice);
this.setImagePath(imagePath);
this.item = {_id: this._id,
             _articleId: this._articleId,
             _name: this._name,
             _price: this._price,
             _quantity: this._quantity,
             _packagingUnit: this._packagingUnit,
             _scaledPrice: this._scaledPrice,
             _imagePath: this._imagePath,
             _total: this.getTotal()
          };

  return this.item;
}


public setId(id) {
  if (id) this._id = id;
  else {
    console.log('An ID must be provided');
  }
}; 


public getId(){
    return this._id;
};

public setarticleId(articleId) {
  if (articleId) this._articleId = articleId;
  else {
    console.log('An ArticleID must be provided');
  }
}; 

public getarticleId(){
    return this._articleId;
};
 
public setName(name) {
  if (name) this._name = name;
  else {
    console.log('A name must be provided');
  }
}; 

public getName() {
  return this._name;
}; 

public setPrice(price) {
  var priceFloat = parseFloat(price);
  if (priceFloat) {
    if (priceFloat <= 0) {
      console.log('A price must be over 0');
    } else {
      this._price = (priceFloat);
    }
  } else {
    console.log('A price must be provided');
  }
};

public getPrice() {
  return this._price;
}; 


public setQuantity(quantity, relative) {
  var quantityInt = parseInt(quantity);
  if (quantityInt % 1 === 0) {
    if (relative === true) {
      this._quantity += quantityInt;
 if (this._quantity >= this._packagingUnit) {
                        this.setPrice(this._scaledPrice);
                    }
                    else {
                        this.setPrice(this._price);
                    };

    } else {
      this._quantity = quantityInt;
    }
    if (this._quantity < 1) this._quantity = 1;

  } else {
    this._quantity = 1;
    console.log('Quantity must be an integer and was defaulted to 1');
  }
}; 

public getQuantity(){
  return this._quantity;
}; 

public setPackagingUnit(packagingUnit){
   if (packagingUnit) this._packagingUnit = packagingUnit;
}; 

public getPackagingUnit(){
  if (this._packagingUnit) return this._packagingUnit;
  else console.log('This item has no Packaging Unit');
}; 

public setScaledPrice(scaledPrice){
   if (scaledPrice) this._scaledPrice = scaledPrice;
}; 

public getScaledPrice(){
  if (this._scaledPrice) return this._scaledPrice;
  else console.log('This item has no Scaled Price');
}; 

public setImagePath(imagePath){
   if (imagePath) this._imagePath = imagePath;
}; 

public getImagePath(){
  if (this._imagePath) return this._imagePath;
  else console.log('This item has no ImagePath');
}; 


 public getTotal(){
    return +parseFloat((this.getQuantity() * this.getPrice()).toFixed(2));

 }; 



toObject(){
  return {
    id: this.getId(),
    articleId: this.getarticleId(),
    name: this.getName(),
    price: this.getPrice(),
    quantity: this.getQuantity(),
    packagingUnit: this.getPackagingUnit(),
    scaledPrice: this.getScaledPrice(),
    imagePath: this.getImagePath(),
    total: this.getTotal()
}
  
}; 
            
public getItem(){
  return this.item;
}
}


i make this ItemService....
but i think i make not good ... 

can you look please my Code ItemService and say me if i on the wrong way by 
converting the ngCartItem Factory

Thanks Benny





can you help me, how i must write this Factory in Typescript?
how looks this in Typescript








Am Sonntag, 21. Mai 2017 17:40:54 UTC+2 schrieb Bernd Wachter:
>
> Hello,
>
> i use the Angular JS Module ngCart in my old Angular JS 1 App
> https://github.com/snapjay/ngCart
>
>
> now i want to bring this ngCart Module to run in my new Angular 4 App
>
>
> can anyone help me how i bring this older Angular Js 1 Module works on 
> Angular 4?
>
> or can anyone convert this to a Angular 4 Module ?
>
> Thanks for helping
>
> Benny
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to