typescript

How to apply some style to the table row in angular material table

天涯浪子 提交于 2021-02-20 16:31:59
问题 I have this table : <div class="table-container"> <table mat-table [dataSource]="dataSource"> <mat-divider></mat-divider> <!-- title column --> <ng-container matColumnDef="title"> <th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.NOTIFY_TITLE' | translate }} </th> <td mat-cell *matCellDef="let element"> {{element.title}} </td> </ng-container> <!-- code column --> <ng-container matColumnDef="description"> <th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.DESCRIPTION' | translate }}

React & TypeScript: Avoid context default value

廉价感情. 提交于 2021-02-20 11:24:29
问题 In the effort to better learn React, TypeScript, and Context / Hooks, I'm making a simple Todo app. However, the code needed to make the context feels cumbersome. For example, if I want to change what a Todo has, I have to change it in three places (ITodo interface, default context value, default state value). If I want to pass down something new, I have to do that in three places (TodoContext, TodoContext's default value, and value=). Is there a better way to not have to write so much code?

Angular: I want to move focus of div from to another on arrow key buttons

半世苍凉 提交于 2021-02-20 09:09:41
问题 I am working on angular project and came to a situation where i have series of div in a row and when user clicks on any div he should be able to move from one div to another using arrow key. Please help. I tried using keypress event but it didn't helped me. Tried finding out similar questions on stackoverflow but all answers where into jquery and i need it in in typescript. moveCell(e){ console.log(e); } .container{ width: 100%; } .cell{ width: 100px; float:left; } .cell:hover, .cell:focus{

Angular: I want to move focus of div from to another on arrow key buttons

北城余情 提交于 2021-02-20 09:06:00
问题 I am working on angular project and came to a situation where i have series of div in a row and when user clicks on any div he should be able to move from one div to another using arrow key. Please help. I tried using keypress event but it didn't helped me. Tried finding out similar questions on stackoverflow but all answers where into jquery and i need it in in typescript. moveCell(e){ console.log(e); } .container{ width: 100%; } .cell{ width: 100px; float:left; } .cell:hover, .cell:focus{

How to import external library and cast it to <any> in Typescript?

情到浓时终转凉″ 提交于 2021-02-20 05:41:26
问题 TypeScript was giving me a compile error that I didn't know how to fix when trying to use a React component I defined: import App = require('./components/views/app/app'); That error went away when I used the import module as <any> : import App = require('./components/views/app/app'); const App2 = App as any; Is there any way to do this in one line, like so? import App = require('./components/views/app/app') as <any>; It would be a great way to import JavaScript files too, without having to do

Passing variables by reference in typescript [Angular 8]

狂风中的少年 提交于 2021-02-20 05:24:46
问题 I have a several variables on the html of the component which are given their values by the typescript file. It is declared in html as follows: <h1>{{myproperty1}}<\h1> <h1>{{myproperty2}}<\h1> <h1>{{myproperty3}}<\h1> In the typescript file they are declared in the global scope as follows: import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], }) export class AppComponent implements OnInit {

Passing variables by reference in typescript [Angular 8]

断了今生、忘了曾经 提交于 2021-02-20 05:24:06
问题 I have a several variables on the html of the component which are given their values by the typescript file. It is declared in html as follows: <h1>{{myproperty1}}<\h1> <h1>{{myproperty2}}<\h1> <h1>{{myproperty3}}<\h1> In the typescript file they are declared in the global scope as follows: import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], }) export class AppComponent implements OnInit {

Typescript type RequireSome<T, K extends keyof T> removing undefined AND null from properties

為{幸葍}努か 提交于 2021-02-20 02:59:29
问题 RequireSome type from another, very simialar question. This question is similar but it should not be a duplicate since here we want to also remove null as well as undefined from properties. Maybe the name shouldn't be Require but something like NonNullable or of this kind. The goal of this type is to specify which fields from a type should not be undefined or null, and return their types without undefined and null. type Question = { id: string; answer?: string | null; thirdProp?: number |

TypeScript: Infer type of generic keyof

倾然丶 夕夏残阳落幕 提交于 2021-02-20 00:30:00
问题 I have types like this: type GenericType<T, K extends keyof T = keyof T> = { name: K; params: T[K] } type Params = { a: 1; b: 2; } const test: GenericType<Params> = { name: "a", params: 2 } When I create an object like test that has property name: "a" I want the type of params to be inferred so that params must be 1 . In my example params has type 1 | 2 which is Params[keyof Params] . But since name is "a" I think it should be possible to limit the type of params to just 1 without specifying

Angular - How to use sum and group by

我怕爱的太早我们不能终老 提交于 2021-02-20 00:24:26
问题 I need to group the records based on ID and display sum of weight. can someone please let me know the sum and group by method in Angular. API Response: data = [ {Id:1, name: 'ABC', weight: 10 }, {Id:1, name: 'ABC', weight: 14 }, {Id:1, name: 'ABC', weight: 16 }, {Id:2, name: 'DEF', weight: 23 }, {Id:2, name: 'DEF', weight: 22 }, {Id:4, name: 'GHI', weight: 44 }, {Id:4, name: 'GHI', weight: 41 } ] Expected output: dataResult = [ {Id:1, name: 'ABC', weight: 40 }, {Id:2, name: 'DEF', weight: 45