Questions tagged [typescript]
TypeScript is a typed superset of JavaScript created by Microsoft that adds optional types, classes, async/await, and many other features, and compiles to plain JavaScript. This tag is for questions specific to TypeScript. It is not used for general JavaScript questions.
60,975 questions
0
votes
0answers
11 views
How do I set the $event returnValue property to null in typeScript
I am using the window.beforeunload event to trap for data changes and warn the user if they need to save data. According to the Mozilla online docs if I set the event return value to null I will not ...
0
votes
0answers
8 views
importing global.d.ts without triple-slash directives
Context: trying to get mocha to run tests on .ts files in my repo.
Problem: when I try running mocha on my entry-tests file:
mocha --compilers ts:ts-node/register ./src/server/backend/specs/index....
0
votes
1answer
17 views
ngOnChanges is not triggered
Hello i am new to angular and having a little issue, here is my code :
import { Component, OnInit,Input, SimpleChange, OnChanges } from '@angular/core';
import { Sensor } from '../../shared/sensor....
-1
votes
0answers
18 views
Angular File Upload - Cannot read property 'item' of undefined
I am trying to upload 3 images. So I created one custom component and calling that from my component. I tried 2 different ways, but no luck. Below is the 2nd approach code. I did console.log. It ...
0
votes
0answers
15 views
Ionic 3 Property 'password' does not exist on type 'User'
i need help with this strangeness that i cant figure out, i keep getting Property 'password' does not exist on type 'User'. even though, i declared password as a string on my user.ts class
user.ts
...
0
votes
0answers
6 views
Angular 6 / UI-Router: Referencing a child state in a lazy loaded module
How do I reference a child state of a (not yet loaded) lazy-loaded state in Angular 6 / UI-Router?
My app has a lazy-loaded state that's only for authenticated users called dashboard which loads ...
0
votes
1answer
10 views
Fixing type compatability for generic with hidden implementations
I was trying to make a Maybe/Optional/Whatever class that could use instead of null/undefined, and I got into this weird problem where my generic class is technically type compatible with any type. My ...
0
votes
0answers
22 views
Why does Typescript have Capitalized and lowercase types? [duplicate]
I notice that types in visual studio code such as string and String as well as number and Number exist in capitalized and lowercase form. I also noticed that when calling native javascript methods and ...
0
votes
0answers
6 views
typed-rest-client readBody failing to return values
So I have the following code below and it returns a 200 (OK) result from the get command but I am unable to get the data that was returned. I've tried readBody() (as seen in the code) and can't get a ...
-1
votes
1answer
24 views
Typescript: how to upload multiple image on one request?
HTML:
<div>
<input
type ="file"
(change)="selectFiles($event)"
multiple="multiple" />
</div>
Function calling the change event
selectFiles(event) {
const ...
0
votes
0answers
6 views
Debugger TypeScript breakpoints not working in Visual Studio 15.8.1
I just upgraded to Visual Studio 2017 (15.8.1) and now when I set a breakpoint in my TypeScript code, the debugger breaks at some unrelated place in my Bundle.js file. I don't even have any ...
1
vote
2answers
24 views
JS: Null-Safe Array Concat
Given:
var a = [1, 2, 3]
var b = null
I need to:
var c = [...a, ...b]
.. but that does not work when a or b is null of course. So in this example b should just not be added, resulting in c = [1, ...
0
votes
1answer
11 views
How to set value to Form in Angular 6 using FormControl
<div class="form-group" [formGroup]="gGroup">
<label for="grouplabel">Group</label>
<select formControlName="groupControl" [(ngModel)]="groupobj" (ngModelChange)="...
0
votes
1answer
15 views
Creating a communication channel between components in Angular
So I have two components, CompA and compA5 which are 3 or 4 levels apart, I want to create a communication channel between the components.
Lets say from component CompA i want to send event to compA5 ...
0
votes
0answers
10 views
how to dynamically generate formGroups within an ngFor
I have an accordion which creates a number of sections x as requested by the user, as follows:
in this case the number of sections was 3, having understood this, I must load the information of the ...
1
vote
1answer
12 views
Double Nested(Multi-Level) Components Angular2
I am trying to generate a dynamic form that will create a dynamic number of questions. I have a parent component, a child-list component, and a chill component which you can see below.
When trying to ...
0
votes
0answers
10 views
How to create styles for Material-UI in TypeScript with the CDN
I am getting a Visual Studio compiler error message: "Cannot find name 'Theme'" on the following line of code:
const styles = ({ palette, spacing }: Theme) => createStyles
How can this be fixed? ...
-1
votes
0answers
10 views
Angular Hybrid Application : ng serve with Typescript
I have an application written in Typescript using AngularJS using Typescript Namespaces.
I wish to write the new components in Angular 2.
I have successfully create the hybrid application by using a ...
-1
votes
0answers
15 views
unable to display Bootstrap 4 Multi-Card Carousel using Angular 6
i am creating a bootstrap 4 multi item carousel using angular 6 where i want to show 3 items and after pressing next the scroll needs to move .
below is what i am trying to achieve code:
but ...
0
votes
0answers
13 views
Taking `typeof` of generic type variable in TypeScript [duplicate]
I have lots of enums that look like this:
enum MyEnum {
foo = 'SomeFoo',
bar = 'SomeBar',
buzz = 'SomeBuzz',
quux = 'SomeQuux',
}
And I want to define complementary types for each of ...
0
votes
1answer
15 views
How do you type partial types in a TypeScript Angular application using an Apollo backend?
Edit: I'm looking for an authority and sourced answer from Graphql-Angular community to provide a best practice example.
For example, we have a Person type defined as such in TypeScript:
interface ...
0
votes
1answer
20 views
How to properly implement nested forms with Validator and Control Value Accessor?
In my application, I have a need for a reusable nested form component, such as Address. I want my AddressComponent to deal with its own FormGroup, so that I don't need to pass it from the outside.
At ...
0
votes
0answers
12 views
DOMContentLoaded async react hydrate possible issues
Will there be any issues if I kick off an async React hydrate operation in the DOMContentLoaded event listener?
My code looks similar to this:
document.addEventListener("DOMContentLoaded", (event) =&...
0
votes
3answers
26 views
How do I map http request response to my defined object in TypeScript
I'm getting to know Angular, TypeScript and RxJS.
I have an http request that returns a JSON. In this JSON there is data that I need to construct my defined object. Let's say, that my object is this:
...
0
votes
0answers
9 views
How to use angular 6 class decorator in a component?
I create a component in angular 6 with sample on how to implement decorators.
So, I create a custom decorator called @Course and set a value there, named Angular 6. Now, how to get that value in my ...
0
votes
1answer
22 views
Issue with Argument of type “” is not assignable to paramerter of type string[] - for angular
I am trying to deploy my application using visual studio and when I run "node_modules\webpack
\bin\webpack.js --env.prod" I get the error below I also added ("strictNullChecks":false) to my ts.config....
0
votes
1answer
15 views
Typescript error in ngrx/effects: computed property name must refer to a built in symbol
I am working with ngrx to implement an app state in my ionic 3.9.2 app (using this tutorial for guidance: https://gonehybrid.com/a-beginners-guide-to-using-ngrx-in-an-ionic-2-app-part-1/)
I am ...
0
votes
0answers
15 views
Three.js Is Quaternion.slerp() slower than Vector3.lerpVectors()
I'm animating a camera in my scene and have been playing with Quaternion.slerp() and Vector3.lerpVectors().
With lerpVectors, I have a function that takes in a Vector3 to look at, and a duration to ...
0
votes
0answers
10 views
Select directive from component Angular5
this is my component:
<ng-template let-model="model" let-template="template">
<div class="ti-tbrd" templateBlockRendererDirective (editing)="onEdit($event)" [info]="...
1
vote
1answer
17 views
How to use jquery.notify in angular
There is a jquery lib: notify.js. I want to use this in my Angular project.
I add the dependency "@types/jquery.notify": "^1.5.0".
And then in my services, import jquery:
import * as $ from '...
2
votes
1answer
22 views
The semantics of @Injectable(providedIn: 'root')?
Just want to make sure I understand the semantics of @Injectable(providedIn: 'root').
Prior to Angular 6 if we import a module from NPM that contains a service we would declare that module in our ...
0
votes
1answer
25 views
How to return dymanic (key, value) pairs in Javascript function
I am trying to write a function that will return dynamic key,value pairs.
SERVICE:
getContentfulEntries(query: QueryEntries, keyQuery?: QueryFilters[]): Observable<any> {
const ...
0
votes
1answer
22 views
Angular 6 rendering HTML tag with ngFor loop with interpolation
i'm having a problem with template rendering (ANGULAR 6) and a library for creating floating panels (jsPanel 6) that is plain javascript. To sum up:
In my template, after rendering it, i have one ...
0
votes
1answer
24 views
Angular: How to use *ngFor with Parent Child components
What's the best way to loop through a child component multiple times, but with different data each time?
For example, within my 'sitelist' component (parent), I want to loop through my 'summary' ...
-2
votes
0answers
28 views
Javascript to typescript code
I am trying to create animated login page and found one template.(https://codemyui.com/registration-login-card-ui-form/).
I want to write javascript code in typescript which will enable some css ...
0
votes
2answers
17 views
Using canActivate or canChildActivate throws error?
Using canActivateChild or canActivate in the child route throws error. This thing worked fine earlier, but there seems to be issue this time. It throws an error:
ERROR in src/app/app-routing.module....
1
vote
0answers
20 views
Strange parsing json to xml in javascript
I have a strange problem. I work with nodeJS and I want to parse json to XML, then send it to remote WebService. So:
1. Download 'soap' and 'js2xmlparser' via npm
2. Create Client:
function ...
2
votes
0answers
18 views
What is the difference between the controls and get methods of the FormGroup object?
I have 2 lines of code that pretty much do the same thing namely:
this.data.affiliateLinkUrl = this.bookLinkForm.controls['affiliateLinkUrl'].value;
this.data.affiliateLinkUrl = this.bookLinkForm....
0
votes
1answer
15 views
Angular - Objects as Select Option Values
I have a form with various select boxes which use objects as the value:
<mat-option [value]="object">
Which works great when I am creating new records via the form. Now when I am editing ...
1
vote
2answers
25 views
Testing a typescript function with a subscribe in it
So I'm testing with Jasmine/Karma and am using Angular 4. I'm trying to test a function that looks like this:
As you can see, this.name assignment is not getting touched. I've tried testing with:
it(...
0
votes
0answers
12 views
Compare angular grid column cell texts against a string array using typescript
I am new to typescript and looking to scrape a list of values from an ag-grid column and compare it against a string array. Here is the function I wrote to achieve that. But my ActualRatingsValues....
0
votes
1answer
12 views
How to extend an interface with an async function?
What might be a good way to go about extending an interface with an async function in TypeScript?
It might be useful to add a property to the async function, serving as something resembling a ...
1
vote
2answers
16 views
TypeScript object with dynamic but required property type
I have the following scenario. I need to create an object with a property that can be one of two possible types (custom classes).
export class MyType1 {
// some properties
}
export class MyType2 {...
1
vote
2answers
40 views
Angular - Make section of string variable bold
Is there any way in which I can make part of a string being assigned to a variable bold?
I have tried the following:
boldTxt = 'bold'
message = 'this text should be ' + this.boldTxt.toUpperCase()....
0
votes
0answers
8 views
Install Metronic with angular 5
I recently bought a theme called Metronic (5..). I installed all the required stuff including the angular 5 CLI version (requirement). I read documentation but I'm not sure I've correctly created the ...
0
votes
0answers
20 views
Error when trying to use Semantic components
I'm trying to use a Semantic UI React Transition component. I have Semantic installed and importing it:
import {
Transition,
} from "semantic-ui-react";
import 'semantic-ui-css/semantic.min.css'...
-1
votes
0answers
10 views
Which encoding these characters in the image - csv file read issue
Could you please clarify what kind of encoding is this in the following image?
I am trying to read a csv file using the code:
reader.readAsText(input.files[0]);
It was returning clear text
But ...
-2
votes
1answer
45 views
How to add select dropdown with numbers from 1 to 10 with each having unique index/value
How to add select dropdown with numbers from 1 to 10 with each option having a unique value and default selected option as 1
HTML
<select [(ngModel)]="selectNum">
<option value=""> &...
0
votes
0answers
6 views
Do you scan the generated JS files from TS fot static code check in a angular project?
I have an angular 6 project written in TypeScript. Currently, I am doing static code scan for .ts source files only.
Should I do the analysis for generated.js files?
What is the best practice in ...
0
votes
1answer
26 views
How to test that I have loaded my JSON - Angular2+
I have an Angular method that simply loads the contents of a locally stored JSON file featuring an array, however I cannot seem to test it.
test.ts (shortened for conciseness)
describe('MyComponent',...