Reactive forms – disabled attribute

I have been using [attr.disabled] because I still like this template driven than programmatic enable()/disable() as it is superior IMO. Change <md-input formControlName=”id” placeholder=”ID” [disabled]=”true”></md-input> to <md-input formControlName=”id” placeholder=”ID” [attr.disabled]=”true”></md-input> If you are on newer material change md-input to mat-input.

In Angular, What is ‘pathmatch: full’ and what effect does it have?

While technically correct, the other answers would benefit from an explanation of Angular’s URL-to-route matching. I don’t think you can fully (pardon the pun) understand what pathMatch: full does if you don’t know how the router works in the first place. Let’s first define a few basic things. We’ll use this URL as an example: … Read more

Warn user of unsaved changes before leaving page

To also cover guards against browser refreshes, closing the window, etc. (see @ChristopheVidal’s comment to Günter’s answer for details on the issue), I have found it helpful to add the @HostListener decorator to your class’s canDeactivate implementation to listen for the beforeunload window event. When configured correctly, this will guard against both in-app and external … Read more

angular2 how to change the default prefix of component to stop tslint warnings

You need to modify two files tslint.json and .angular-cli.json, suppose you want to change to myprefix: In the tslint.json file just modify the following 2 attributes: “directive-selector”: [true, “attribute”, “app”, “camelCase”], “component-selector”: [true, “element”, “app”, “kebab-case”], change “app” to “myprefix” “directive-selector”: [true, “attribute”, “myprefix”, “camelCase”], “component-selector”: [true, “element”, “myprefix”, “kebab-case”], In the angular.json file just … Read more

How to use Bootstrap in an Angular project?

Provided you use the Angular-CLI to generate new projects, there’s another way to make bootstrap accessible in Angular 2/4. Via command line interface navigate to the project folder. Then use npm to install bootstrap: $ npm install –save bootstrap. The –save option will make bootstrap appear in the dependencies. Edit the .angular-cli.json file, which configures … Read more