How to bind to model with Angular Material ?

MatButtonToggle component doesn’t implement ControlValueAccessor therefore you can’t use ngModel on it. ngDefaultControl was introduced for other purposes. MatButtonToggle is supposed to be a part of mat-button-toggle-group. But if you want to use it as a standalone component and bind model to it here is some example of how you can do it: <mat-button-toggle [checked]=”myFlagForButtonToggle” … Read more

mat-form-field must contain a MatFormFieldControl and already imported

Actually the error doesn’t mean a module import problem, but that you’re using the mat-form-field without a valid control. The problem is here : <mat-form-field> <mat-checkbox formControlName=”active”>Active</mat-checkbox> </mat-form-field> MatChebox isn’t intended to be contained in a mat-form-field but yeah its name is not very clear … Keep just in mind that mat-form-field is the component … Read more

Angular InjectionToken throws ‘No provider for InjectionToken’

After asking on the official angular repository, it turns out to be a simple solution. Instead of passing the service name as a string, you’ll have pass the tokens through the component into the view into another component. Globally define the injection token I did this alongside my service itself to make it easier to … Read more

PathLocationStrategy vs HashLocationStrategy in web apps

For me the main difference is that the PathLocationStrategy requires a configuration on the server side to all the paths configured in @RouteConfig to be redirected to the main HTML page of your Angular2 application. Otherwise you will have some 404 errors when trying to reload your application in the browser or try to access … Read more