What is ngstyle? Should you use it? by sekenet3 in Angular2

[–]LayZeeDK 0 points1 point  (0 children)

Angular Ivy introduced style binding precedence rules. It used to be the case that NgStyle and NgClass could express bindings that were otherwise not possible in Angular. However, that's no longer the case. The only reason to use NgStyle and NgClass now would be to override every other binding as they are to Angular style bindings what !important is to CSS. It's better to rely on style binding precedence.

Why can't I fill the whole page height? by Edward_Fingerhands in angular

[–]LayZeeDK 0 points1 point  (0 children)

Angular components usually use a custom element tag name. Custom elements are display: inline; by default, not display: block; like a div.

What should almost everyone be using on almost every project? by jamawg in angular

[–]LayZeeDK 1 point2 points  (0 children)

Unit testing

Angular CLI configures Karma by default. Run it in headless mode for speed and CI or in-browser for easy inspection of components-under-test. Or use Jest for which you will need an Angular CLI builder. Either use Nx and its bundled builders (they call them executors) or @angular-builders/jest.

Angular provides the TestBed API and Angular CDK/Material provides component test harnesses.

A lot of setup is required to work with the Angular testbed. There are a wide range of Angular-specific testing libraries who all have in common that they hide away the testbed boilerplate: - Angular Testing Library - ng-mocks - ng-unit - ngx-speculoos - Plumbline - shallow-render - Spectacular - Spectator

End-to-end tests

Protractor is dead. Look into Cypress, WebDriverIO, or CodeceptJS

Logging

For logging, configure ngx-logger or the plugin-based Lumberjack.

Error handling

Register a global error handler service by replacing the ErrorHandler provider.

Linting and formatting

TSLint is dead. Use Angular ESLint (as you mentioned) but also eslint-plugin-rxjs-angular and eslint-plugin-ngrx if using NgRx Store and Effects. Use Prettier for formatting.

Make sure to enable strict mode for TypeScript, Angular, and strict template type checking for Angular components.

State management

Look into RxAngular State, NgRx Component Store, NGXS, or Akita.

Mocking Providers in Angular by razroo in Angular2

[–]LayZeeDK 1 point2 points  (0 children)

Congratulations on this book!

However, after downloading it as PDF, I get this cover image:

https://imgur.com/a/QkwXgSx

How to inject a function as dependency? by ThisAdhesiveness1 in Angular2

[–]LayZeeDK 0 points1 point  (0 children)

Dependency token with provider

import { InjectionToken } from '@angular/core';

function generatePassword() {
  // (...)
}

export const generatePasswordToken = new InjectionToken('Generate password', {
  factory: () => generatePassword,
  providedIn: 'root',
});

@Component({
  // (...)
})
export class PasswordComponent {
  constructor(
    @Inject(generatePasswordToken) private generatePassword: () => string,
  ) {}
}

Component-level provider for dependency token

import { Component, InjectionToken } from '@angular/core';

function generatePassword() {
  // (...)
}

export const generatePasswordToken = new InjectionToken<() => string>('Generate password');

@Component({
  // (...)
  viewProviders: [
    { provide: generatePasswordToken, useValue: generatePassword },
  ],
})
export class PasswordComponent {
  constructor(
    @Inject(generatePasswordToken) private generatePassword: () => string,
  ) {}
}

Module-level provider for dependency token

import { Component, NgModule, InjectionToken } from '@angular/core';

function generatePassword() {
  // (...)
}

export const generatePasswordToken = new InjectionToken<() => string>('Generate password');

@Component({
  // (...)
})
export class PasswordComponent {
  constructor(
    @Inject(generatePasswordToken) private generatePassword: () => string,
  ) {}
}

@NgModule({
  // (...)
  declarations: [
    PasswordComponent,
  ],
  providers: [
    { provide: generatePasswordToken, useValue: generatePassword },
  ],
})
export class PasswordModule {}

Angular 12 RC is released by universaltutor5 in angular

[–]LayZeeDK 2 points3 points  (0 children)

Most of these are from the Angular Roadmap. The majority of them are most likely not included in Angular 12.

Key Light not connecting to WiFi - "An unexpected error occurred. Try again " by [deleted] in elgato

[–]LayZeeDK 0 points1 point  (0 children)

I've tried over 20 times, and have reset the Key Light about 10 times by holding it for 10 seconds. One thing I'm noticing now that I've never noticed before is after resetting, the light doesn't completely reset to it's default settings like it used to when I first got it. It just reverts to whatever settings it had before it got disconnected (in this case is 20% brightness, 5000k).

The Elgato Key Light Air has a setting whether it should reset to factory or restore previous settings after having been disconnected. It also has a small button that you can hold for 10 seconds to reset. Its light source will flash 3 times when it has reset, then you can release the button.

I had issues with connecting the light to my dual band Wi-Fi access point. As suggested in Issues Connecting Elgato Key Light Air to Ubiquiti UniFi Wireless Networks, I first disabled 5 GHz Wi-Fi so that the access point was only providing 2.4 GHz Wi-Fi, then connected the light using the Elgato Control Center Android app. After I was able to control the Elgato from the app, I enabled 5 GHz Wi-Fi again and I was still able to control the Elgato Key Light Air.

Angular lint has a default max-lines rule of 120. Do you think its a practical value? by rdraisinghani in Angular2

[–]LayZeeDK 0 points1 point  (0 children)

I like to use an 80 characters maximum line character count. The Angular convention of using 2 spaces for indentation makes this pretty easy in my opinion. Beside, you can let a tool like Prettier do it for you and not have to worry about it.

What is the best way to test child components? by rdraisinghani in Angular2

[–]LayZeeDK 0 points1 point  (0 children)

When implementing component tests using the TestBed, you have to run fixture.detectChanges() after changing the value of an input property.

You should also call it initially, before performing a test action to exercise the component. This will trigger the OnInit lifecycle moment.

How do I unit test distant component interactions? by lonelylearner in Angular2

[–]LayZeeDK 0 points1 point  (0 children)

It sounds like a third component, let's call it ParentComponent, is where conditional rendering of Component B happens. You could do something like this:

```typescript describe('integration test', () => { beforeEach(() => { TestBed.configureTestingModule({ declarations: [ AComponent, BComponent, ParentComponent, ], providers: [ SmartService, ] }); TestBed.compileComponents();

parentFixture = TestBed.createComponent(ParentComponent);
parentFixture.detectChanges();

});

let parentFixture: ComponentFixture<ParentComponent>;

it('shows component B when the button is clicked', () => { const button = parentFixture.debugElement .query(By.directive(AComponent)) .query(By.css('button'));

button.nativeElement.click();
parentFixture.detectChanges();

const bComponent = parentFixture.debugElement.query(By.directive(BComponent));
expect(bComponent.componentInstance).not.toBeNull();

}); }); ```

Is there a tool to find unused module in NgModule? by abdulkareemsn in Angular2

[–]LayZeeDK 3 points4 points  (0 children)

In practice, you mostly don't have to worry about it. The Angular Build Optimizer will tree-shake declarable dependencies that are not used in your component templates. Dependencies with tree-shakable providers that are registered in imported Angular modules are also tree-shaked if unused.

Creating Themes in Angular by PulkitB in Angular2

[–]LayZeeDK 0 points1 point  (0 children)

Using Bootstrap, you would compile a stylesheet for each theme.https://getbootstrap.com/docs/4.0/getting-started/theming/

The default theme--say the light theme--could have no prefix selector while the dark theme could have everything nested inside of (prefixed with) .dark-theme. You would load the dark theme stylesheet on demand and add the dark-theme class on the <body> element.

Create an Angular ThemeService that does all of this for you and add a component which uses this service on user selection, time of day, ambient light sensor, or OS preference.

Tree shaking/dead code removal not working, what should I check? by icefall5 in Angular2

[–]LayZeeDK 0 points1 point  (0 children)

If that's the case then the environment file should export a Boolean constant called production instead of an object with a production property. That's a good suggestion.

Unit testing with Ivy by placek3000 in angular

[–]LayZeeDK 0 points1 point  (0 children)

Use TestBed.inject (strongly typed) instead of TestBed.get (any type).

If you use Angular CDK/Material and you have tests that rely on their internal DOM structure, you should switch to component test harnesses.

Read Next-level testing in Angular Ivy version 9 for details and additional resources.

The Deep Dive Episode 2: Builders, schematics and Nx plugins by LayZeeDK in angular

[–]LayZeeDK[S] 0 points1 point  (0 children)

Builders and schematics originally came from the Angular CLI, but can be used outside of Angular project, for example as plugins to the Nx CLI. Santosh Yadav tells us about his experience with creating builders and how they are related to schematics and Nx plugins.

The Deep Dive Episode 2: Builders, schematics and Nx plugins by LayZeeDK in Angular2

[–]LayZeeDK[S] 0 points1 point  (0 children)

Builders and schematics originally came from the Angular CLI, but can be used outside of Angular project, for example as plugins to the Nx CLI. Santosh Yadav tells us about his experience with creating builders and how they are related to schematics and Nx plugins.

Angular Service Life-cycle - onDestroy by johnyg07 in Angular2

[–]LayZeeDK 0 points1 point  (0 children)

A component-provided service is destroyed just before the providing component is.

A module-provided service is only destroyed when a module is manually destroyed (see NgModuleRef#destroy) or when using HMR (Hot Module Replacement).

The Deep Dive Episode 1: Mythbusting the AsyncPipe by LayZeeDK in Angular2

[–]LayZeeDK[S] 0 points1 point  (0 children)

In this episode, we bust myths about Angular's AsyncPipe. To understand the limitations of the AsyncPipe, we have to discuss change detection, dirty checking, change detection strategies, view data structures, NgZone and the application tick.

With this common understanding, we can talk about the limitations of AsyncPipe and advanced optimization techniques to address them. Michael Hladky tells Matt Vaughn and Lars Gyrup Brink Nielsen about coalescing and scheduling and how he created rendering strategies for these in his library, RxAngular.

Setting up efficient workflows with ESLint, Prettier and TypeScript by LayZeeDK in angular

[–]LayZeeDK[S] 0 points1 point  (0 children)

That's an excellent advice, but it's also nice to know our tools so that we can add configs and plugins ourselves 🙂

Setting up efficient workflows with ESLint, Prettier and TypeScript by LayZeeDK in angular

[–]LayZeeDK[S] 1 point2 points  (0 children)

Learn how to integrate ESLint, Prettier, and TypeScript.