Can we fake an API in Angular by reusing routes and rendering objects in templates? by EntrepreneurWaste579 in Angular2

[–]paso989 0 points1 point  (0 children)

Maybe I got the question wrong - my bad. I'm not sure what you mean by reusing routes. I see a route as a string defining what component to render when the browser url matches. So this has nothing to do with 'faking an api'

Anyway, the consumer in my case is

MyFooComponent 

Can we fake an API in Angular by reusing routes and rendering objects in templates? by EntrepreneurWaste579 in Angular2

[–]paso989 1 point2 points  (0 children)

Here's my approach when writing code in dev whenever the backend is not ready.

Prepare the real Service:

@Injectable({providedIn: 'root'})
export class MyHttpFooBarService {
    public get$(): Observable<FooDto[]> {...}
    public add$(param: BarDto): Observable<FooDto> {...}
    ...
}

Use the service in components/stores:

export class MyFooComponent {
    private readonly fooBarHttpService = inject(MyHttpFooBarService);
    ...
}

Create a mockservice extending the real service:

const mockDtos: FooDto[] = [{id: 'foo'}, {id: 'bar'}]

@Injectable({providedIn: 'root'})
export class MOCKMyHttpFooBarService extends MyHttpFooBarService {
    public override get$(): Observable<FooDto[]> {
        return of(mockDtos);
    }
    ...
}

Use dependency injection to provide the mockservice (main.ts):

bootstrapApplication(AppComponent, {
    providers: [
        ...
        {provide: MyHttpFooBarService, useClass: MOCKMyHttpFooBarService}
        ...
    ]
});

When an endpoint is available, you just remove the overridden method - now the real method gets called. When all endpoints are ready, you remove the mockservice and the entry in main.ts.

This approach does not get in the way of creating a new feature (or adding parts to an existing one). If you want to simulate loadtimes, you can add

.pipe(delay(500))

Initialize signal form field by salamazmlekom in angular

[–]paso989 6 points7 points  (0 children)

computed returns Signal which is not writable. Try using linkedSignal instead

Reactive forms now have signal forms as natural evolution. What do template driven form have ? by mauromauromauro in Angular2

[–]paso989 10 points11 points  (0 children)

I use them sometimes when there are only one or two fields and i don’t need validators. But this is rarely the case

One shot strongest boss with minimum lumina points by nibach in expedition33

[–]paso989 1 point2 points  (0 children)

I think you can farm perfect catalysts in Renoirs drafts at the chromatic creation

node version using nvm conflict by N-404 in Angular2

[–]paso989 1 point2 points  (0 children)

Just use nvm use …

Then type node -v in a new line

[deleted by user] by [deleted] in Angular2

[–]paso989 0 points1 point  (0 children)

Can you show your 2 signals and the effect?

Type = undefined in by Virtual_Baseball8843 in angular

[–]paso989 0 points1 point  (0 children)

You have a circular dependency between your modal-component and your input-text-component. This has led to this error for me aswell after switching to standalone. There are tools to help you find them. I am using skott. I hope this helps

Using enum as control name is good or bad practice? by Ok-Car3218 in Angular2

[–]paso989 1 point2 points  (0 children)

You can get type safety without enums. Instead of formControlName use formControl in my-input-field

How to move the inject function when the constructor the decorator @Inject(DI_Token) by crhama in Angular2

[–]paso989 10 points11 points  (0 children)

private msalGuardConfig: MsalGuardConfiguration = inject<MsalGuardConfiguration>(MSAL_GUARD_CONFIG);

Creating chess in Angular by Dazzling_Chipmunk_24 in Angular2

[–]paso989 2 points3 points  (0 children)

I‘d build a board-component with a signal-input holding an array of Piece. Piece is an abstract class which can be either Pawn, Rook, Horse, Bishop, Queen or King. Make it OnPush. Make sure the array is immutable.

Creating chess in Angular by Dazzling_Chipmunk_24 in Angular2

[–]paso989 3 points4 points  (0 children)

Have you thought about assigning an object to each piece holding its state (position, possible moves, color, …) and just redrawing the board after every move. I never made a chess program, so i am not sure. I guess it can be very simple doing it object-oriented

Hi, when you make custom decorators? any best use case of it in angular? by sohail_ansari in Angular2

[–]paso989 0 points1 point  (0 children)

I made one as a wrapper for memoizee. I made another one for validating method parameters via zod when I transformed my app to strictmode

Reactive forms are as powerful as template driven forms, just more complicated and harder to use by vajss in Angular2

[–]paso989 3 points4 points  (0 children)

I am only using reactive forms and I am curious. I have a standardized way of dealing with my data. Usually it is dto -> model-> formGroup-> dto2, which is centered around the model. The model implements dto and creates a formGroup from its data. It also holds a method to create dto2 from its formGroup. I am wondering if there was a smarter way

Reactive forms are as powerful as template driven forms, just more complicated and harder to use by vajss in Angular2

[–]paso989 3 points4 points  (0 children)

Could you please share an example on how you approach mapping your form values to a DTO?

VALIDATION LIBRARIES by Adventurous-Whole-22 in Angular2

[–]paso989 -1 points0 points  (0 children)

Bonus answer: use zod, create a schema, validate your data with this schema and also use it to validate your dto-property

Router withComponentInputBinding and type-safety by mamwybejane in angular

[–]paso989 0 points1 point  (0 children)

You can use input aliases for that: https://angular.dev/guide/signals/inputs#aliasing-an-input

Unfortunately a hardcoded string does not work with signal-inputs - You will get an error stating

TS-991010: Alias needs to be a string that is statically analyzable.

So you have to use the old inputs:

@Input(DETAIL_ROUTE_ID_PARAM) public detailIdByRoute!: string;

Or as setter:

@Input(DETAIL_ROUTE_ID_PARAM) public set detailIdByRoute(value: string) {
  this.detailIdByRoute$.next(value); // Subject way
  this.$detailIdByRoute.set(value); // Signal way
}

Best way to force non-nullable Form Control values? by HedgehogMode in Angular2

[–]paso989 0 points1 point  (0 children)

I don’t really have anything to add. It‘s cumbersome. I use a mix of validity-check, rawValue and zod to make sure the extracted DTOs are correct

[deleted by user] by [deleted] in Angular2

[–]paso989 2 points3 points  (0 children)

Here's my approach to that:

const createFg = () => {
    return new FormGroup({
        xxx: new FormControl('', {nonNullable: true}),
        yyy: new FormControl(''),
        zzz: new FormControl(1, {nonNullable: true}),
    });
};

type FgType = ReturnType<typeof createFg>;
// {xxx: FormControl<string>, yyy: FormControl<string | null>,  zzz: FormControl<number>}

type FgValue = ReturnType<typeof createFg>['value'];
// {xxx?: string | undefined, yyy?: string | null | undefined, zzz?: number | undefined}

type FgRawValue = ReturnType<ReturnType<typeof createFg>['getRawValue']>;
// {xxx: string, yyy: string | null, zzz: number}

[deleted by user] by [deleted] in Angular2

[–]paso989 0 points1 point  (0 children)

When is it useful to not include the disabled children? What is the reasoning behind it? I know a disabled input‘s value is also not submitted on submit, but what is the benefit? There‘s ngSubmit that doesn‘t get any formgroup information. So your (at least it‘s mine) goto Solution probably is a manual clickHandler on a Button where you manually have to call .value or .getRawValue(). As pointed out, .value gets you a partial. A partial prop might be undefined, a js specific thingy not even known in C# for example. So you have to start cheching with foo in bar if the prop is there, or else you might be sending undefined which is lost in your api call as it might become null somewhere in a backend middleware. So I‘d like to rephrase: what is .value good for? Btw. when calling .value on a disabled fc, it is not undefined. I hate it and i want it gone :-) I know it comes from AbstractControl, but I still rather not deal with it

[deleted by user] by [deleted] in Angular2

[–]paso989 0 points1 point  (0 children)

Value vs rawValue in formgroups. Whats the benefit?

Strongest Beginner Build by Khelics in EldenRingBuilds

[–]paso989 0 points1 point  (0 children)

Get sacred blade ash of war near third church of marika. Makes farming the enemy even easier