Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. createForm(){
  2. this.getGeral()
  3. this.getTiposTarefas()
  4. this.formulario = this.fb.group({
  5. 'tipo_tarefa':[this.tarefa.tipoTarefa.id, Validators.compose([Validators.required])], // Cant set default values cuz the array is object is undefined
  6. 'data_tarefa': [this.tarefa.data_tarefa, Validators.compose([Validators.required])],// Cant set default values cuz the array is object is undefined
  7. 'inicio_tarefa': [this.tarefa.inicio, Validators.compose([Validators.required])],// Cant set default values cuz the array is object is undefined
  8. 'fim_tarefa': [this.tarefa.fim, Validators.compose([Validators.required])]// Cant set default values cuz the array is object is undefined
  9. });
  10. }
  11.  
  12. import { Component, OnInit } from '@angular/core';
  13. import { NavParams, ModalController } from '@ionic/angular';
  14. import { TarefadetalheService } from './tarefadetalhe.service';
  15. import { Tarefa } from '../../models/tarefa.model';
  16. import { TipoTarefa } from '../../models/tipotarefa.model';
  17.  
  18. import { FormGroup, FormBuilder, Validators } from '@angular/forms';
  19. @Component({
  20. selector: 'app-tarefas-detalhe',
  21. templateUrl: './tarefas-detalhe.page.html',
  22. styleUrls: ['./tarefas-detalhe.page.scss'],
  23. })
  24. export class TarefasDetalhePage implements OnInit {
  25. idTarefa = null
  26. tarefa: Tarefa
  27. tiposTarefas : TipoTarefa[]
  28. formulario: FormGroup
  29. constructor(
  30. private navParams: NavParams,
  31. private getTarefaDetalhe: TarefadetalheService,
  32. private modalController:ModalController,
  33. public fb: FormBuilder) { }
  34.  
  35. ngOnInit() {
  36.  
  37. this.createForm()
  38. }
  39.  
  40. getGeral(){
  41. this.idTarefa = this.navParams.get('id_tarefa');
  42. this.getTarefaDetalhe.recuperaDetalhes().subscribe((data: Tarefa)=>{ //passar o id da tarefa como parametro no recupera detalhes
  43. this.tarefa = data
  44. })
  45. }
  46.  
  47. getTiposTarefas(){
  48. this.getTarefaDetalhe.recuperaTiposTarefas().subscribe((data: TipoTarefa[])=>{
  49. this.tiposTarefas = data
  50. console.log(this.tiposTarefas) // here it has information
  51. })
  52. console.log(this.tiposTarefas) // here it has not information
  53. }
  54.  
  55. createForm(){
  56. this.getGeral()
  57. this.getTiposTarefas()
  58. this.formulario = this.fb.group({
  59. 'tipo_tarefa':[this.tarefa.tipoTarefa.id, Validators.compose([Validators.required])], // Cant set default values cuz the array is object is undefined
  60. 'data_tarefa': [this.tarefa.data_tarefa, Validators.compose([Validators.required])],// Cant set default values cuz the array is object is undefined
  61. 'inicio_tarefa': [this.tarefa.inicio, Validators.compose([Validators.required])],// Cant set default values cuz the array is object is undefined
  62. 'fim_tarefa': [this.tarefa.fim, Validators.compose([Validators.required])]// Cant set default values cuz the array is object is undefined
  63. });
  64. }
  65. closeModal()
  66. {
  67. this.modalController.dismiss();
  68. }
  69. }
  70.  
  71. <ion-content padding *ngIf="tarefa != null">
  72. <form [formGroup]="formulario">
  73. <h4>
  74. <ion-icon name="list-box"></ion-icon> Geral
  75. </h4>
  76. <ion-grid>
  77. <ion-row>
  78. <ion-col size="8">
  79. <ion-label position="floating">Tipo de Tarefa</ion-label>
  80. <ion-select [formControlName]="tipo_tarefa" okText="Confirmar" cancelText="Cancelar">
  81. <ion-select-option *ngFor="let tipo of tiposTarefas" [value]="tipo.id">{{tipo.descricao}}</ion-select-option>
  82. </ion-select>
  83. </ion-col>
  84. </ion-row>
  85. </ion-grid>
  86. <h4>
  87. <ion-icon name="calendar"></ion-icon> Horário
  88. </h4>
  89. <ion-item-divider></ion-item-divider>
  90. <ion-grid>
  91. <ion-row>
  92. <ion-col size="5">
  93. <ion-label position="stacked">Data</ion-label>
  94. <ion-datetime [formControlName]="data_tarefa" display-format="DD-MM-YYYY" max="2050-10-31" picker-format="DD-MM-YYYY"></ion-datetime>
  95. </ion-col>
  96. <ion-col size="3">
  97. <ion-label position="stacked">Inicio</ion-label>
  98. <ion-datetime [formControlName]="inicio_tarefa" display-format="HH:mm" picker-format="HH:mm" ></ion-datetime>
  99. </ion-col>
  100. <ion-col size="3">
  101. <ion-label position="stacked">Fim</ion-label>
  102. <ion-datetime [formControlName]="fim_tarefa" display-format="HH:mm" picker-format="HH:mm"></ion-datetime>
  103. </ion-col>
  104. </ion-row>
  105. </ion-grid>
  106. <h4>
  107. <ion-icon name="person"></ion-icon> Cliente
  108. </h4>
  109. <ion-item-divider></ion-item-divider>
  110. <ion-grid>
  111. <ion-row>
  112. </ion-row>
  113. </ion-grid>
  114. </form>
  115. </ion-content>
  116.  
  117. createForm(){
  118. this.getGeral();
  119. this.getTarefaDetalhe.recuperaTiposTarefas().subscribe((data: TipoTarefa[])=>{
  120. this.tiposTarefas = data;
  121. this.formulario = this.fb.group({...put the fields...});
  122. console.log(this.tiposTarefas) // here it has information
  123. })
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement