Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. {"Cargo": string,
  2. "idFuncionario": 0,
  3. "idCadastro": 0,
  4. "cadastro": {
  5. "idCadastro": 0,
  6. "nome": "string",
  7. "razao": "string",
  8. "documento": "string"
  9. }
  10.  
  11. "dtAtualizacao": "2019-02-22T17:32:38.049Z",
  12. }
  13.  
  14. postFuncionario(funcionario : Funcionario){
  15.  
  16. try {
  17. var body = JSON.stringify(funcionario);
  18. var headerOptions = new Headers({'Content-Type':'application/json'});
  19. var requestOptions = new RequestOptions({method : RequestMethod.Post,headers : headerOptions});
  20. return this.http.post(this.localUrl+'Create'
  21. ,body,
  22. requestOptions).map(x => x.json());
  23. }
  24.  
  25. catch (error) {
  26. return Observable.throw(error)
  27. }
  28.  
  29. }
  30.  
  31. onSubmit(form:NgForm){
  32.  
  33.  
  34. if (form.value.idFuncionario == null) {
  35. this.service.postFuncionario(this.form.value)
  36. .subscribe(data => {
  37. this.toastr.success('Novo registro gravado com sucesso!', 'Funcionário Cadastrado')
  38. console.log(this.service.funcionario )
  39. console.log(this.form.value)
  40. console.log(form.value.idFuncionario)
  41. this.resetForm()
  42. })
  43. }
  44.  
  45. <input type="number" class="form-control" name="idFuncionario" placeholder="ID Funcionário"
  46. [(ngModel)]="service.funcionario.idFuncionario" value="{{service.funcionario?.idFuncionario}}">
  47.  
  48. <input type="text" class="form-control" name="nome" placeholder="Nome" #nome="ngModel"
  49. [(ngModel)]="service.funcionario.cadastro.nome" value="{{service.funcionario?.cadastro.nome}}">
  50.  
  51. import {Cadastro} from './cadastro.model'
  52.  
  53.  
  54. export class Funcionario {
  55.  
  56. Cargo : string
  57. idFuncionario : number
  58. cadastro : Cadastro
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement