title: Angular(Ionic) Services and model dependencies
body: <p>I was told that for a Ionic project I must use a service for each object.</p>
  
  <p>my models:</p>
  
  <pre><code>export class Document{
      idDocument: number;
      listFields: Fields[];
  }
  export class Field{
      idParentDocument: number;
      idLinkToOtherDocument: Document;
  }
  </code></pre>
  
  <p>my services :</p>
  
  <pre><code>export class DocumentService{
      constructor(private http: httpService, private fieldService: FieldService){}
  
      getFields(document: Document){
         this.fieldService.getFieldsByDocumentId(document.id);
         //gets the fields of the document
      }
  
      getDocument(id: number){
         //gets the document and its fields
      }
  }
  
  export class FieldsService{
      constructor(private http: httpService, private documentService: DocumentService){}
  
      getParentDocument(field: Field){
         //gets the parent document of the field
      }
  
      getLinkedDocument(field: Field){
         //gets the linked document of the field
      }
  
      getFieldsByDocumentId(id: number){
         //gets the fields by document Id
      }
  }
  </code></pre>
  
  <p>Sometimes I need to access objects from other objects like in my example, but as you can imagine this ends up in circular dependencies. I don't know what I am supposed to do, in java as an example you would simply have to call the functions but in angular you can't. I can go back to my previous design pattern where all functions was in objects and not in service, and I had to pass all other services (database service, server service...) but it would be a huge refactoring for something I was told was bad design (and I find it better with objectServices, I have access to all services without passing them as arguments)</p>
  
  <p>What should I do ?</p>