Can an angular 2 component be used with an attribute selector?

Yes, the selector property of the @Component decorator is a CSS selector (or a subset of): selector: ‘.cool-button:not(a)’ Specifies a CSS selector that identifies this directive within a template. Supported selectors include element, [attribute], .class, and :not(). Does not support parent-child relationship selectors. Source: Angular Cheat Sheet / Directive Configuration, which @Component inherits. That way … Read more

angular 2 typescript An implementation cannot be declared in ambient contexts

An implementation cannot be declared in ambient contexts You most probably have your file named as foo.d.ts instead of foo.ts. That marks it as a declaration file (more on that https://basarat.gitbooks.io/typescript/content/docs/types/ambient/d.ts.html) and you cannot put logic in these as you are declaring what logic exists elsewhere.

Angular 2/4 How to style angular material design snackbar

md-snackbar provides a service to provide custom config. One the properties of config is extraClasses that allows to add CSS classes to the snack bar container (doc). extraClasses can be used with ::ng-deep to override the default CSS classes. Here’s an example: component.ts: Requires following import in the component: import {MdSnackBar, MdSnackBarConfig} from ‘@angular/material’; (providing … Read more

Chrome – Debug Angular/Typescript – how to navigate to ts file

Angular uses webpack and all type script files are listed under it. To select your target typescript file, Chrome’s Developer tool (F12). Go to Source tab, Select Chrome “webpack://”->”src/app” -> your typescript file. Or in older version of chrome follow this path “webpack://”->”.”->”src/app” -> your typescript file ( See the image file). Or Ctrl+P to … Read more

password and confirm password field validation angular2 reactive forms

This is what eventually worked for me – this.addEditUserForm = this.builder.group({ firstName: [”, Validators.required], lastName: [”, Validators.required], title: [”, Validators.required], email: [”, Validators.required], password: [”, Validators.required], confirmPass: [”, Validators.required] },{validator: this.checkIfMatchingPasswords(‘password’, ‘confirmPass’)}); checkIfMatchingPasswords(passwordKey: string, passwordConfirmationKey: string) { return (group: FormGroup) => { let passwordInput = group.controls[passwordKey], passwordConfirmationInput = group.controls[passwordConfirmationKey]; if (passwordInput.value !== passwordConfirmationInput.value) { return … Read more

angular2-cli include custom fonts

For the people arriving here by searching: Install with npm: npm install roboto-fontface –save Add to styles in .angular-cli.json (apps[0].styles): “styles”: [ “styles.css”, “../node_modules/roboto-fontface/css/roboto/roboto-fontface.css” ], That’s all! Edit: since Angular 6 this file is called angular.json instead of angular-cli.json. Adding fonts still works the same way as before.