This is my html:
<div class="container">
<form [formGroup]="form" (ngSubmit)="postCreateTypeFields()" style="width:400px; margin: 0 auto;">
<h1>Types Fields</h1>
<div class="required-field-block">
<input formControlName="name" type="text" placeholder="Nome" class="form-control">
<div class="required-icon">
<div class="text">*</div>
</div>
</div>
<div class="required-field-block">
<input formControlName="version" type="text" placeholder="Versão" class="form-control">
<div class="required-icon">
<div class="text">*</div>
</div>
</div>
<button type="submit" class="btn btn-primary" >Criar</button>
</form>
</div>
Component
import { Component, OnInit, ModuleWithProviders } from '@angular/core';
import { FormBuilder, FormGroup, NgControl } from '@angular/forms';
import { CreateTypeFieldsService } from '../create-type-fields.service';
@Component({
selector: 'app-create-type-fields',
templateUrl: './create-type-fields.component.html',
styleUrls: ['./create-type-fields.component.css'],
providers: []
})
export class CreateTypeFieldsComponent implements OnInit {
private _createTypesFields: Model.CreateTypesFields;
private form: FormGroup;
constructor(private _createTypeService: CreateTypeFieldsService, private builder: FormBuilder) {
this.form = this.builder.group({
name: '',
version: ''
})
}
ngOnInit() {
this._createTypeService.postCreateTypeFields(this._createTypesFields)
.subscribe( success => {
if(success.Result){
//anything here
}
},
error =>{
}
);
}
}
Service
import { Injectable } from '@angular/core';
import { HttpClient, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Configuration } from './app.constants';
import {RequestOptions, Request, RequestMethod} from '@angular/http';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
@Injectable({
providedIn: 'root'
})
export class CreateTypeFieldsService {
private actionUrl: string;
private url: 'http://localhost:56758/api';
constructor(private http: HttpClient, private _configuration: Configuration) {
this.actionUrl = _configuration.ServerWithApiUrl + 'TypesFields/';
}
public postCreateTypeFields(itemName: Model.CreateTypesFields): Observable<any> {
const toAdd = JSON.stringify({ ItemName: itemName });
return this.http.post(this.actionUrl, toAdd, httpOptions);
/
}
}
When I try to consume the API, it gives this error
TypeError: _co.postCreateTypeFields is not a function
How do I resolve this?