Posts by Eduardo Vargas • 3,413 points
194 posts
-
-2
votes1
answer124
viewsA: Initialize variable with Typescript defined interface
estatisticaNps: RetornoEstatisticaAvaliacao = {QuantidadeDetrator: 0...} Only start properties directly
-
0
votes1
answer19
viewsA: Undetected error: 'nativeElement' property cannot be read
In the ngOnInit html has not yet been redenrized. Try adding this code to ngAfterViewInit.
-
0
votes1
answer46
viewsA: Angular - Route opens wrong component
import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { PersonListComponent } from './person-list/person-list.component'; import {…
-
0
votes1
answer93
viewsA: Angular does not recognize variable inside a Javascript Function, integration with Pagseguro
Try it this way PagSeguroDirectPayment.onSenderHashReady((response)=>{ if(response.status == 'error') { return false; } //Nesse caso ele reconhece o this como um objeto do tipo…
-
1
votes1
answer26
viewsA: Delete record using NGRX and effects
The problem is that its effect is waiting for an object with the property payload and you’re sending a command call Try it this way: this.store.dispatch(DELETE_COMANDA({payload: comandaId}));…
-
1
votes1
answer274
viewsA: Sort Angular Component List
The best would be to first order your list ordemProdutosOrdenada = ordemProdutos.sort((a,b)=> a.posicao - b.posicao) ai vc can use ngComponentOutlet inside an ngfor to dynamically instate its…
-
2
votes1
answer33
viewsA: Immutability in the angular components
This is a complex question that would be better explained in a lecture than in a stackoverflow answer. The first thing you have to notice is that components are classes and in your case these files…
-
1
votes1
answer80
viewsA: How to set value in a formBuilder.array in Angular?
Because it is an array vc has to set the interim array or to set a value only use the at method this.formulario.patchValue({ 'departments': [{ code: '01' }] }) or else…
-
0
votes2
answers167
viewsA: Pass value to array - angular
this.formGroup.value['couponPlan'] = this.formBuilder.array(this.plansids.map(plan=> new FormControl(plan)); // ou plan.propriedade
-
3
votes1
answer62
viewsA: How to avoid that when enrolling in an observable it receives the last amount issued?
By default Behaviorsubject sane hot that is has this behavior of issuing the value when subscribed, so they need a value to boot. In your case best use only Subject even though by default they are…
-
2
votes1
answer270
viewsA: How to apply a conditional style at angular 8
You can use ng Class <p [ngClass]="{ 'sua-classe': appointment.status==='teste', 'sua-outra-classe': appointment.status==='banana' }" >
-
-1
votes1
answer84
viewsA: Capture data from all select elements in HTML with Angular
In this case you have to use formArray inves from the group this.formArray = new FormArray( this.data.map(value=> new FormControl(value)) // os dados que seu array é baseado, é bem ruim chamar…
-
0
votes1
answer91
viewsA: Http to Httpclient (Angular)
http client does parse para json automatico then the code: return this.http.get(`${this.url}/grupos`).map(res => res.json()); flipped: return this.httpClient.get(`${this.url}/grupos`);…
-
1
votes1
answer32
viewsA: A single Arrayobject for presentation and modification
The problem seems to be that you’re copying the same reference, try so: this.productsToShow = {...products}; this.productsToEdit =Object.assign({}, products); Or to have totally another object:…
-
0
votes1
answer24
viewsA: Insert (Value)"Slider value" into an Angular Nativescript Label
Do So: <Slider [value]="value" minValue="0" maxValue="100" (valueChange)="onSliderValueChange($event)"> </Slider> TS: value=1 constructor(){}... onSliderValueChange(args) { let slider =…
-
1
votes1
answer97
viewsA: Angular page composed of several components
The information below is from official style guide and from my experience but overall in relation to component architecture depends a lot on the application also and despite good practices there is…
-
2
votes1
answer47
viewsA: how to disable or enable input text through a reactive radio input
You can do it like this: <div class="ui-g-12 ui-md-4 center-zone"> <input-radio formControl="controle" id="controle" theme="boolean" label="tem controle?" ></input-radio>…
-
0
votes2
answers70
viewsA: Angular paging and javascript sending events always returns the same page
'a' widgets no value (click)="goToPage(currentPage + 1)" ts: goToPage($event: any) { this.currentPage=$event; this.paginate.emit($event); console.log(this.currentPage); }…
-
0
votes1
answer32
viewsA: Case Sensitive attribute
Hello, although Typescript type your data it will come exactly as it comes from the backend. There is a difference between typing and casting. If you speak pro typescript that your back will send…
-
1
votes1
answer133
viewsA: Circular Dependency with Providedin
@Injectable({ providedIn: "root" }) With a few rare exceptions, you should always use provideIn: Root, this is because service are singletons and when you add it to root it is like a Singleton for…
angularanswered Eduardo Vargas 3,413 -
1
votes1
answer84
viewsA: Dependency injection problems in Angular unit tests
You can use the useValue or useClass to use something that would be a stub or a mock of your service. For example, let’s assume that you have a service that returns a user via http: providers:[{…
-
1
votes2
answers51
viewsA: Lazy-Loaded and angular charging shapes
The first form { path: 'rota', loadChildren: '../module/function.module#FunctionModule'} It is the oldest form of how it was done when Angular2 came out, however because it is a path within a…
-
3
votes1
answer42
viewsA: How to get the last n elements of an Observable?
getUltimosDados(n: number): Observable<Objeto[]>{ return this.httpClient.get<Objeto[]>(this.enderecoDaApi + '/objetos/').pipe( map(arr=>arr.slice(-n)) );…
-
-1
votes1
answer101
viewsA: Transforming object array into a specific data structure
Try something like that: arra.reduce((acc, ite)=>{ acc[ite.IBX]={ ...acc[ite.IBX], [ite.GroupName]: ite }; return acc; },{})
-
1
votes1
answer54
viewsA: Index repeating when the page is exchanged in ngx pagination
Try adding pagination properties when adding a book. this.favs.push(this.books[(this.p*this.count)+i]) Or better do it in html: (click)="addFav(book)" ai vc have the whole object of the book and not…
-
2
votes2
answers3390
viewsA: How to apply Dynamic Mascara in angular input?
The most elegant way to do this is to change the value of Mask based on length without ngIf <input type="text" name="telefone" id="telefone" class="form-control" formControlName='telefone'…
-
5
votes2
answers1134
viewsA: How to get an Observable from an array item?
You have to map the answer only to the item you want: return this.http.get<Exemplo[]>(PATH).pipe( map(response => { //map do rxjs return response.filter(item=>item.id===id); // filter do…
-
0
votes2
answers166
viewsA: Ionic (Angular) - ngModel inside an ngFor
By the time you get your products from your backend you have to add this field for each respective product. this.produtosService.pegarProdutos().subscribe(produtosResponse=>{…
-
1
votes1
answer159
viewsA: How to create function with dynamic feedback type?
You have to use Generics: getObjeto<T>(): <T>{ return this.objetoCreator.create(); } getData<T>(): Observable<T> { return this.http.get<T>(PATH); } To call it:…
-
1
votes1
answer28
viewsA: Disabled error ao utilizar junto com formcontrolName: The 'value' should be a Valid Javascript Date
Change there from new to value AgendaData: new FormControl({value: new Date(), disabled: true}, [Validators.required]) And remove disabled from your html.
-
1
votes2
answers763
viewsA: Async/Await x Sync
It doesn’t make much sense to compare synchronous and asyncronous methods since they have different purposes. think like this imagine that you want to make a cake if you already have all the…
-
0
votes1
answer252
viewsA: Is there any way to force an option of a <mat-option> by a service?
Just have the form control with the same value as the value of your option. For example: this.form.get('emptyTitle').setValue(this.indices[0]._id)
-
1
votes1
answer384
viewsA: Uncaught Error: Template parse errors: 'app-home' is not a known element:
You have to add the Exports tag to the components you want to be visible to other modules. import { NgModule } from "@angular/core"; import { CommonModule } from "@angular/common"; import {…
-
3
votes2
answers234
viewsA: How to join two arrays at the angle
With the es6 has the possibility to do with deconstructing arrNovo = [...arr1, ...arr2] // voce pode fazer com quantos arrays quiser e a ordem importa.
angularanswered Eduardo Vargas 3,413 -
0
votes1
answer1539
viewsA: How to make a filter component with angular 8
In your case for having an input in one component and you need the result of it in another component that has no relation I believe that the best would be to have a service to make this…
-
4
votes1
answer66
viewsA: How to color a button corresponding to a selected value?
There is a much easier way to do this, just have a property selected for each element of the array that starts empty and then based if you have selected an ng class. import { Component,…
-
2
votes2
answers193
viewsA: Segregate CSS in the construction of Angular components?
The more uncoupled your architecture is always better. Today you think you will always be together, but you never know tomorrow, maybe you want to use the same header in another project. So in this…
-
0
votes1
answer587
viewsA: Angular Error: Property 'Controls' does not exist on type 'Abstractcontrol'
There is nothing in Indice 0 so from Undefined, to enter a new value do so: this.constituicaoForm.get('tipoAtivo').push("tipoTeste");
-
0
votes2
answers2253
viewsA: Angular 8 / ngx-bootstrap / Datepicker
I did so using Moment: import { NgbDateParserFormatter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap'; import * as moment from 'moment'; import { Injectable } from '@angular/core'; @Injectable()…
-
0
votes1
answer109
viewsA: HOW TO SAVE A SUBSCRIBE RETURN IN A VARIABLE?
Dude, overall, your code is really bad ngOnInit() { const today = Date.now() this._schedulesService.getSchedules() .pipe( map(response=>response.filter(item=>item.dtPlanejada ==…
-
0
votes1
answer644
viewsA: Unit Service Testing Using Karma (typescript/angular)
I would do something like this: it('get should call correct api with correct payload', () => { let httpClient = TestBed.get(HttpClient); const obj = { response: 'superResponse' }; const mockHttp…
-
1
votes1
answer3133
viewsA: Typescript Error Property 'name' does not exist on type 'Object'
Try it this way: valor:any; validar(){ this.storage.get('refresh').then(val => { this.loginProvider.refresh(val).subscribe( (res:any)=> { this.valor=res.nome; this.storage.set('token',…
-
0
votes1
answer1243
viewsA: Angular Typeerror: Cannot read Property '0' of Undefined in Table with 2 ngFor
Tries to initialize its property as an empty array consultas: Consulta[] = [];
angularanswered Eduardo Vargas 3,413 -
2
votes4
answers4308
viewsA: Load component only after finishing HTTP requests
You can do something like this loading=true ngOnInit(){ seuService.fazerRequest(response=>{ //suaLogica loading=false; }) Html <componente *ngIf="!loading">…
-
1
votes1
answer64
viewsA: The 'value' should be a Valid Javascript Date instance. When using the Kendo ui’s date Picker
Apparently this library expects an instance of the Date type, for that you have to create an object of this type parsing the date that comes from the back formcontrol.setValue(new Date()) or…
-
1
votes2
answers434
viewsA: How to recover documents from a Firestore(Firebase) collection in the right way?
Observables is how angular deals with asyncronism. let imagens: Array<any> = []; this.db.collection('contatos').doc(key).collection('imagens') .snapshotChanges() .subscribe(response=> {…
-
1
votes2
answers355
viewsA: What are the main differences and advantages of using Shadow DOM and Virtual DOM?
First let’s start with the SHADOW DOM which is used by the angular and webcomponents The shadow dom is nothing more than the method that the angular and the webComponents api uses to encapsulate…
-
1
votes4
answers993
viewsA: How to pass/receive data to components via routing
constructor( private route: ActivatedRoute, ) { } ngOnInit(){ let lastRoute=this.route; while(lastRoute.firstChild){ lastRoute=firstChild } …
-
0
votes1
answer520
viewsA: Change formBuilder array value
To change the formsReactive value use the setValue method() alterarEndereco(i:number,endereco:FormGroup) { // (<FormControl>this.form.controls['enderecos'][i].controls.estado).setValue('RR');…
angularanswered Eduardo Vargas 3,413 -
1
votes1
answer669
viewsA: Directive: lock double click on a button
I would do something like this: import { Directive, HostListener } from '@angular/core'; @Directive({ selector: '[blockClicks]' }) export class NoDblClickMatDirective { lastClick = 0; constructor()…