Error consuming method getAll angular 6

-9

This is the error:

  

src / app / create / create-fields / create-fields.component.ts (29,16): error   TS2345: Argument of type '(data: Result) = > void   not assignable to parameter of type '(value: TypeFieldItem) = > void '.   Types of parameters 'data' and 'value' are incompatible.       Type 'TypeFieldItem' is not assignable to type 'Result'.         Property 'error' is missing in type 'TypeFieldItem'.

I am clearing my code, taking out the generic ones and typing my methods, which is the right thing to do. And I started to get errors and I was eliminating, but this one I'm kind of lost in solving. My Component

export class CreateFieldsComponent implements OnInit {

  createForm :FormGroup;
  private _createFields: Model.CreateFields;

  private operUrl: 'api/TypesFields';
  public dataSourceType: Model.TypeFieldItem[];

  constructor(private _createFieldService: FieldsService, private builder: FormBuilder) { 
    this.createForm = this.builder.group({
     name: '',
     typeField:  ''     
   });
 } 

  ngOnInit() {

    this._createFieldService
    .getAllTypeFields()
    .subscribe((data: Model.Result<Model.TypeFieldItem>) => {
      this.dataSourceType = data.itens;
    });    
  }

  onPostCreateFields(){
    let formValue = this.createForm.value;
    this._createFields ={
      name: formValue.name,
      typeField: {
        typeFieldId: <string>formValue.typeField
      }
    };

        this._createFieldService.postCreateFields(this._createFields)
        .subscribe( success => {
          if(success.Result){
        }
      },
        error =>{
      }
    );
  }
}

Here I get the error ( data: Model.Result)

this._createFieldService
        .getAllTypeFields()
        .subscribe((data: Model.Result<Model.TypeFieldItem>) => {
          this.dataSourceType = data.itens;
        }); 

My service

public getAllTypeFields(): Observable<Model.TypeFieldItem> {
    return this.http.get<Model.TypeFieldItem>(this.actionUrl1);
  }

Of course, my model

declare namespace Model{
    export interface Result<T>{
        error: boolean,
        itens: Array<T>,
        message: string
    }

    export interface OperatorItem{
        operatorId: string,
        name: string,
    }

    export interface CreateTypeFieldItem{
        typeFieldId: string,
        name: string
    }

    export interface TypeFieldItem{
        typeFieldId: string,
        name: string
    }

    export interface FieldsItem{
        _typeField: string,
        name: string,
        typesFields: TypeFieldItem
    }

    export interface ApplicabilityItem{
        aplicabilityId: string,
        name: string,
        context: string,
        typePaymentDetailsModel: TypePaymentItem,
        typeDeliveryDetailsModels: TypeDeliveryItem,
        marketPlace: boolean
    }

    export interface OperationsItem{
        id: string,
        applicabilityId: string,
        field: string,
        operator: string,
        value: string
    }

    export interface TypePaymentItem{
        id: string,
        sgpTypePaymentId: number,
        name: string
    }

    export interface TypeDeliveryItem{
        id: string,
        sgpTypeDeliveryId: number,
        name: string
    }
}

How do I resolve this?

EDIT1

I did this to solve

Service
public getAllTypeFields(): Observable<Model.TypeFieldItem[]> {
    return this.http.get<Model.Result<Model.TypeFieldItem>>(this.actionUrl1)
    .pipe(map((res) => res.itens));

  }

My method in my component

this._typefield
      .getAllTypeFields<Model.Result<Model.TypeFieldItem>>()
      .subscribe((data: Model.Result<Model.TypeFieldItem>) => {
        this.dataSource = data.itens;
      })

And this is the error I'm getting right now

  

ERROR in   src / app / GetUpdateDelete / type-fields / type-fields.component.ts (24,5):   error TS2558: Expected 0 type arguments, but got 1.

How do I make it work? How do I resolve this new error?

    
asked by anonymous 27.07.2018 / 16:01

1 answer

-3

I have decided this way: Component

this._createFieldService
    .getAllTypeFields()
    .subscribe((data: Model.TypeFieldItem[]) => {
      this.dataSourceType = data;
    }); 

Service

public getAllTypeFields(): Observable<Model.TypeFieldItem[]> {
    return this.http.get<Model.Result<Model.TypeFieldItem>>(this.actionUrl1)
    .pipe(map((res) => res.itens));

  }
    
27.07.2018 / 21:03