Mask for an Input to allow phone numbers?

Angular5 and 6: angular 5 and 6 recommended way is to use @HostBindings and @HostListeners instead of the host property remove host and add @HostListener Working Online stackblitz Link: https://angular6-phone-mask.stackblitz.io Stackblitz Code example: https://stackblitz.com/edit/angular6-phone-mask Official documentation link https://angular.io/guide/attribute-directives#respond-to-user-initiated-events Angular2 and 4: Plunker >= RC.5 original One way you could do it is using a directive that injects NgControl and manipulates the … Read more

How to use jQuery with Angular?

Using jQuery from Angular2 is a breeze compared to ng1. If you are using TypeScript you could first reference jQuery typescript definition. TypescriptDefinitions are not required since you could just use any as the type for $ or jQuery In your angular component you should reference a DOM element from the template using @ViewChild() After the view has been initialized you can … Read more

How to use `trackBy` with `ngFor`

On each ngDoCheck triggered for the ngForOf directive, Angular checks what objects have changed. It uses differs for this process and each differ uses the trackBy function to compare the current object with the new one. The default trackBy function tracks items by identity: It receives the current item and should return some value. Then … Read more

Angular 5: “No provider for ControlContainer”

The ControlContainer is a abstract class which is extended by the AbstractFormGroupDirective inside the ReactiveFormsModule. The error is thrown if you’re using the ReactiveFormsModule and a <form>-element without a FormGroup bound to it via [formGroup]=”myForm”. To fix this error you have to create a FormGroup and bind it to your form: Also make sure you … Read more

How to enable production mode?

You enable it by importing and executing the function (before calling bootstrap): But this error is indicator that something is wrong with your bindings, so you shouldn’t just dismiss it, but try to figure out why it’s happening.

Angular error: Please add a @NgModule annotation

You’re trying to “import” a component in SomeModule. You import modules and declare components, which is exactly what the error message tells you — you tried importing a directive SomeComponent. Unexpected directive ‘SomeComponent’ imported by the module ‘SomeModule’. Move the SomeComponent from imports to declarations.