angular-material2

how to select default items in angular material 2 select multiple

我的未来我决定 提交于 2019-12-04 12:13:07
I'm working on angular 2 material app, I have a case where there is multiselect element and in that I have a list with checkbox so I can select multiple items at a time. I'm able to to that with angular material component, but what I want is 2-3 items to be checked by default, and if I select/deselect a particular item, then I should get checked/selected flag as true/false. <md-select multiple="true" [(mgModel)]="test"> <md-option *ngFor="let l of list" [value]="l"> {{l.name}} </md-option> </md-select> var list = [{name:'abc'},{name:'cbv'},{name:'hgf'},{name:'rty'},{name:'fdv'},{name:'vbg'}]

Angular 2 material nested md-list-item

喜夏-厌秋 提交于 2019-12-04 12:02:48
问题 Using Angular 2 with material design, trying to get nested lists in sidenav I have code like <md-sidenav #sidenav class="sidenav" mode="over" opened> <md-nav-list> <md-card class="user-card"> <md-card-header> <div md-card-avatar class="user-avatar"></div> </md-card-header> </md-card> <md-divider></md-divider> <md-list-item *ngFor="let category of ategories"> <a md-line>{{ category.name }}</a> </md-list-item> </md-nav-list> </md-sidenav> which works fine and looks something like Now When i try

Angular 2 Material 2 Sidenav Toolbar collapse like Navigation Drawer

China☆狼群 提交于 2019-12-04 11:26:49
问题 I have a sidenav and a nested toolbar toolbar.html <md-sidenav-container fullscreen> <md-sidenav #sidenav mode="side" color="primary"> <md-toolbar color="primary"><span>Sidenav</span></md-toolbar> <button md-button class="sidenav-link" (click)="sidenav.close()"> <md-icon>home</md-icon><span class="title"> HOME</span> </button> <button md-button class="sidenav-link" (click)="sidenav.close()"> <md-icon>home</md-icon><span class="title"> HOME</span> </button> </md-sidenav> <app-toolbar [sidenav]

Angular 2+ material mat-chip-list formArray validation

本秂侑毒 提交于 2019-12-04 11:10:00
How do I validate that a mat-chip has been added to the mat-chip-list . I am using ReactiveForms. I have tried with the required validator. The value can be a list of names, so I need to make sure that there is atleast 1 name in my list of names before I can submit the form. If the list is empty then mat-error should display the error message. Using the required validator makes the form invalid, regardless of adding names to the list. EDIT: Reactive Forms I have tried to make a custom validator, and I am now using Reactive Forms instead of Template driven forms, but I cannot get it to work. I

angular 5 material 2 - auto complete getting data from external api

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 11:02:57
问题 I'm using angular 5 and material 2. In ts file, I have this proeperty: filteredOptions: Observable<any[]>; This property is going to have an array of values to show in the autocomplete field. [{ id:'1', name: 'teste 1'}, {id:'2', name: 'teste 2'}, {id:'3', name: 'teste 3' }] This array of values come from the database and it is going to be shown after the user type something. html file: ## <form class="example-form"> ## <mat-form-field class="example-full-width"> ## <input type="text"

Expand input width dynamically to the length of string

时光总嘲笑我的痴心妄想 提交于 2019-12-04 10:09:02
I am trying to create an input field that expands at least in width dynamically with the length of the string the user entered, probably even multiline. Is that possible with an input element in Angular Material 2? With the textarea field from Angular Material 2 I only managed to expand the textarea in height, not in width with the following code: <mat-form-field (keydown.enter)="onEnter()" floatPlaceholder="never"> <textarea matInput placeholder="Autosize textarea" matTextareaAutosize matAutosizeMinRows="1" matAutosizeMaxRows="8"> </textarea> </mat-form-field> also on StackBlitz . In case of

angular material 2 custom component with ng value accessor

左心房为你撑大大i 提交于 2019-12-04 07:09:29
I a working on angular 4.4 + material beta12 custom component and not able to figure out what is wrong in my implementation I am trying to achieve the below custom input Task: set value to formControl, once I got data from server(data.productTeam is data-can see in code) on edit, formcontrol should be updated with values (eg:P12DT2H231M) Issues: I am not able to bind default value to formcontrol. Without ngDefaultControl (No value accessor for form control with name: 'productTeam' error occuring) dashboard.component.js this.CRForm = this.fb.group({ productTeam: [data.productTeam || ''] }); In

How to keep mat-datepicker calender open, even after selecting a date from calendar?

点点圈 提交于 2019-12-04 06:57:59
问题 I want to keep mat-datepicker open in a particular div. I used opened=true property but it gets closed after selecting a date. 回答1: This should work for you: Add this to your input (click)="_openCalendar(picker)" #keepOpen This to your mat-datepicker (closed)="_openCalendar(picker)" And this to your typescript: @ViewChild('keepOpen') _input: ElementRef; _openCalendar(picker: MatDatepicker<Date>) { picker.open(); } Don't forget to import ViewChild and ElementRef That's my working sample on

Angular Material 2 browser autofill for mat-select not working

点点圈 提交于 2019-12-04 06:04:45
I have a form that represents an address and I'm using mat-select for the state/province. Unfortunately it's not autofilling the state/province (I'm assuming because it's not a native select). Here is my markup: <mat-form-field> <mat-select placeholder="State" [(ngModel)]="state" autocomplete="billing address-level1"> <mat-option *ngFor="let s of states" [value]="s.abbreviation">{{ s.name }}</mat-option> </mat-select> </mat-form-field> I'm not sure if I'm missing something or if the browsers autofill isn't working because mat-select isn't a native control. Anyone have any idea how to make

Angular 4 + Material 2 SASS compile error “File to import not found or unreadable”

你离开我真会死。 提交于 2019-12-04 05:02:52
I'm trying to use a custom theme but I keep getting the error: { "status": 1, "file": "/home/adam/Projects/test-material/src/unicorn.scss", "line": 1, "column": 1, "message": "File to import not found or unreadable: ~@angular/material/theming.\nParent style sheet: /home/adam/Projects/test-material/src/unicorn.scss", "formatted": "Error: File to import not found or unreadable: ~@angular/material/theming.\n Parent style sheet: /home/adam/Projects/test-material/src/unicorn.scss\n on line 1 of src/unicorn.scss\n>> @import '~@angular/material/theming';\n ^\n" } I've installed a brandy new Angular