Questions tagged interface

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

Typescript interface – add new value dynamically or create the interface dynamically

I have an Angular Material Table. Obviously, I have an interface from which is created the dataSource for the table. Is there any possibility to add a new value dynamically in the interface Or at least to create the interface dynamycally? Because the data which is coming from the backend it’s unknown. Example: from this: […]

How should I implement the model interface when one of the identifiers in the response is a number in an Angular app

sample response from the api : "results":[ { "id":16228, "name":"ABCD", "preview":"/d8a/d8a61a3a12e52114afdbc28f2c813f5c.jpg", "data":{ "480":"https://mdb.net/steam/6693661/movie480.mp4", "max":"https://mdb.net/steam/6693661/movie_max.mp4" } I have the interface as follows: interface Movie { data: { max: string; 480: string; }; } When I try to <video class="movie" controls *ngFor="let trailer of results" > <source src="{{ trailer.data.480 }}" <——– Error here type="video/mp4" /> Your browser […]

By Hasith
Published
Categorized as angular, angular12, interface, numeric, response Tagged , , , ,

Typescript – Use base itnerface as generic type

In an Angular application, I am using a base interface with some common properties and two child interfaces extending it: interface BaseConfig { id: number; name: string; type: ConfigType } interface UserConfig extends BaseConfig { socialNr: number; } interface OrderConfig extends BaseConfig { shipDate: Date; } enum ConfigType { User: ‘user’, Order: ‘order’ } The […]

How to add a new key and value to an existing object in an array (Angular)

I want to push a new key and corresponding value to an already existing object. My object is returned after subscribing to a WEB API endpoint. Within the object returned, I want to add a "QuantityOnHand" key and value. I have attempted the following, however, it is not as I want it. branchProduct: BranchProduct; getProductByName() […]

By SeventhWarhawk
Published
Categorized as angular, arrays, interface, object, typescript Tagged , , , ,

Using generics is there any way to initialize object with default property values from an interface in typescript angular

I have an interface with properties of different data types in it. Interface ISample { Id: number Due: date Name: string Address: Array<string } Need a pure generic logic without help of external packages Expected object { id:0 Due: new Date() Name: null Address: [] } Source: Angular Questions

How to pass properties from interface in Angular component?

Ho to implement interface in component? Is it possible to avoid the @input part and do it on different way? Interface: export default interface Example { title: string; } Component: import { Component, Input } from ‘@angular/core’; @Component({ templateUrl: ‘./Example.html’, styleUrls: [‘./Example.scss’], }) export default class Example{ @Input() title: any; } Source: Angular Questions

By Fresh
Published
Categorized as angular, components, interface, typescript Tagged , , ,

How to declare and access object value from html in angular 11 interface

Can I declare this type of interface? interface groups{ name:”; address:”; headOfGroup:{ id:”; } But I can not access id of headOfGroup from HTML <div class="form-group" *ngIf="users"> <label class="col-form-label" for="select1">Select</label> <select id="select1" name="user" [(ngModel)]="groups.headOfGroup.id" class="form-control" required> <option value="">Please select</option> <option *ngFor="let u of users" [value]="u.id">{{u.firstName}} {{u.lastname}} </option> </select> </div> error shows: vendor.js:59773 ERROR TypeError: Cannot […]

Filling a select with data from another interface

I have a table colaborator linked with another one: area, on the front, I want to show in a select the areas available when entering a new colaborator. The thing is, I have a reactive form in angular, wich uses the colaborador (colaborator in spanish) interface, but I also have another interface area, so how […]

By jhon
Published
Categorized as angular, forms, interface, select, typescript Tagged , , , ,

How can I autogenerate an interface in an Angular component?

I am trying to find a way how to autogenerate interface in component. Here is an example: export default interface Person { id: number; name: string; } export default class Person { } So what I am asking is, how can I pass the properties from the interface in this class automatically, so I wont […]

How can I define an interface for this type of response in Angular?

I’m having problems with defining an interface for the following response: API Res looks like this: https://pastebin.com/BiXLaSvJ I want to access every event in the events array and check contents in it’s context. So something like this if (events.event.gameEnd.context.win > 0) { do something} How can I create an interface for this? Source: Angular Questions

By Alan Knap
Published
Categorized as angular, interface, typescript Tagged , ,
1 2 3 6

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