Questions tagged typescript

Explore the latest questions and answers asked by our top developers.

wait for subscribe to finish and call save in angular6?

I have to complete validation functions before calling the save function. I am calling API (Async in C#) for validation function and it does not wait until the return result and proceeding in to save which is wrong. submit() { this.validateBeforeSave(); this.Save(); } validateBeforeSave() { // Here calling API action ( used Async and Await […]

By ANR
Published
Categorized as angular, c#, typescript Tagged , ,

Is using async/await in promise request more efficient? [closed]

What is the best way to make requests? I have an http request method in project.service.ts. I can make the request with the following structure: getProjectById(projectId: number) { return this.http.get<Project>(`${this.url}/search/projects/${projectId}`).toPromise(); } And call it with the following structure in project.component.ts: async getProject(projectId: number) { this.isLoading = true; try { this.project = await this.api.projects.getProjectById(projectId); } finally […]

Angular testing error. NullInjectorError: No provider for ActivatedRoute! and TypeError: Cannot read properties of undefined (reading ‘title’)

have some errors with testing my website made with Angular. I do not have much experience in angular, I am getting this error whenever I try running my angular test. This my login.component.spec.ts file looks like import { ComponentFixture, TestBed } from ‘@angular/core/testing’; import { LoginComponent } from ‘./login.component’; import { DebugElement } from ‘@angular/core’; […]

By Aminson
Published
Categorized as angular, angular-test, typescript Tagged , ,

How to use typescript variables in css files?

I am using Angular, my goal is to be able to use a string declared in typescript inside a CSS file. I am trying to set the background image of a navbar component. Later on, the background image path will be received from a database service, that’s why I need it to be in the […]

By Saul Martinez
Published
Categorized as angular, background-image, css, typescript Tagged , , ,

Custom Validation for dynamically generated textboxes in Angular

The code for dynamically generated textboxes uisng *ngFor <tr *ngFor="let computer in _Computers; let i = index;"> <td>{{computer.Name}}</td><td>{{computer.Optional}}</td> <td> <input matInput [formControl] = "frmCtrl" name="UnitofPrice" [(ngModel)]="computer[i]"> </td> <td>{{computer.UnitofPrice}}</td> Typescript code public frmCtrl: FormControl = new FormControl(”, this.customValidator()); customValidator() { return (control: AbstractControl): { [key: string]: boolean } | null => { if ((!control.value)) { return […]

By Billy
Published
Categorized as angular, javascript, typescript Tagged , ,

Converting Array of object to another array of objects

I have an array of objects like in the following structure. [ { TaskID: “1001”, TaskName: “task1”, AID: “10”}, { TaskID: “1002”, TaskName: “task2”, AID: “10”} ] I have to create an array from the above array to the following structure. [ { “TaskID”: 1, “Value”: “1001”, “AID”: 10 }, { “TaskID”: 2, “Value”: “task1”, […]

By sarasm
Published
Categorized as angular, arrays, typescript Tagged , ,

Angular stop component from running after it has been clicked off of

Currently, I have a sidebar that allows me to click on individual components. These components refresh API calls to get data. However, when I click off the components to another component, the old component keeps on refreshing API data, even though it is not needed as I have clicked off from it. Here is a […]

By GolfBravo
Published
Categorized as angular, refresh, settimeout, typescript Tagged , , ,

Getting Module not found error when upgrade angular v12 to v13

Hi developers and contributors, I am struggling to find out what is the issue with the following error: ./src/app/models/type/ModelType.ts:2:0-44 – Error: Module not found: Error: Resolving to directories is not possible with the exports field (request was ./) This error came when I upgraded my angular version from v12 to v13 (also upgraded some older […]

By Vitomir
Published
Categorized as angular, typescript Tagged ,

Undefined: including a service inside another service – Angular 2

My NotificationService is included in my GlobalService but when I call any NotificactionService function it says: Cannot read properties of undefined (reading ‘warn’). What I’m doing wrong? I think it is related to scope issues. Thanks in advanced! Here is my NotificationService code import { Injectable } from ‘@angular/core’; import { MatSnackBar, MatSnackBarConfig } from […]

By 4aLifeTime
Published
Categorized as angular, scope, service, typescript Tagged , , ,

Angular Can’t loop over data for chart

I have a problem. I am using NGX-Charts for drawing charts, so now I want to draw a line chart. Here is the HTML: <ngx-charts-line-chart [legend]="false" [showXAxisLabel]="false" [showYAxisLabel]="false" [xAxis]="true" [yAxis]="true" [timeline]="false" [results]="accountData"> </ngx-charts-line-chart> First I filled accountData like this in the typescript file: accountData = [ { name: "Users", series: [ { name: "January", value: […]

By A Vreeswijk
Published
Categorized as angular, javascript, typescript Tagged , ,
1 2 3 1,624

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq