Passing input values to Dialog Component [duplicate]

open will give you the component instance , means you can inject what ever you want to it like this : openDialog() { let dialogRef = this.dialog.open(DialogOverviewExampleDialog); let instance = dialogRef.componentInstance; instance.text = “This text can be used inside DialogOverviewExampleDialog template “; console.log(‘dialogRef’,dialogRef); } Then obviously inside the DialogOverviewExampleDialog template you can do : this … Read more

error TS: Property ‘dataset’ does not exists on type ‘Element’

The property dataset does not exist on type Element, but does exist on HTMLElement. You need to make sure it’s of this type before proceeding. It also works to adjust your for loop a bit: for (const timelineEl of timelineEls) { if (timelineEl instanceof HTMLElement) { const progress = self.getProgress(timelineEl); const timelineKey = timelineEl.dataset.scrollTimeline; // … Read more

String interpolation in Typescript, replacing ‘placeholders’ with variables

Use a template string which are much better than String.Format in my opinion as they do not suffer from poor indexing (wrong placeholder) issues: var text = “blah blah”; var strTest = `This is a ${text}`; console.log(strTest); If I do not know the name of the variables I need to pass in?? Then wrap in … Read more

How to get one file as output of angular cli

Angular CLI natively doesn’t support this. There are other solutions, including further processing with other tooling after Angular CLI finishes doing its thing, but this will hinder or remove the debugging capabilities Angular provides out-of-the-box. As the ng eject command is also being deprecated, the option to reconfigure webpack is not as attractive as it … Read more

Error: TypeError: ‘process.env’ only accepts a configurable whileinstall windows-build-tools

I had the exact same problem. First I tried to do npm install –global –production [email protected] but didn’t work then npm config set msvs_version 2022 but still didn’t work. Finally I tried to download node version 17.9.1 and retried the command and it worked!! So here are the steps: Step 1: uninstall Node version 18.12 … Read more

Karma Jasmine – Uncaught TypeError: __webpack_require__(…).context is not a function

I had the same issue. For some reason, in our other app doing angular update automatically deleted some code in test.ts, namely: const context = require.context(‘./’, true, /\.spec\.ts$/); context.keys().forEach(context); and the declaration of require above that. I did that in my other app manually and so far it works. Maybe someone knows the reason for … Read more

.detectChanges() not working within Angular test

It turns out this is due to using ChangeDetectionStrategy.OnPush in the component. Using OnPush only allows you to call .detectChanges() one time, so subsequent calls will fail to do anything. I’m not familiar enough with Angular to fully understand why. I was able to produce the required behaviour by overriding the ChangeDetectionStrategy in my TestBed … Read more

How do I add svg files via MatIconRegistry in unit tests?

can just do: import { MatIcon } from ‘@angular/material/icon’; import { MatIconTestingModule } from ‘@angular/material/icon/testing’; describe(‘MyComponent’, () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [MyComponent, MatIcon], imports: [MatIconTestingModule], }).compileComponents(); })); … }); This will generate a test icon rendering without the HTTP request. NOTE: Newer versions of Angular, e.g., >16, may produce an error unless … Read more

Different routes same component

you can solve it by adding routes const routes: Routes = [ { path: ‘experience’, children: [ { path: ‘pending’, component: ExperienceComponent }, { path: ‘requests’, component: ExperienceComponent }, ] }] and in ExperienceComponent import import { ActivatedRoute } from “@angular/router”; and in constructor add this parameter constructor(public route: ActivatedRoute) and inside constructor get url … Read more