[英]How can I vertically align angular + material mat-checkbox not in form group?
I have two situations: 我有两种情况:
One, is where I'm using a FORM GROUP with using angular 5 + Angular Material Design. 一是在我使用FORM GROUP的同时使用angular 5 + Angular Material Design的地方。
Here's my code for multiple checkboxes 这是我的多个复选框的代码
<div *ngSwitchCase="'checkboxField'" class="checkbox-field">
<div *ngIf="!field?.properties?.hideTitle">{{field?.properties.title}}</div>
<div class="checkbox-label" *ngFor="let
element of field?.elements">
<mat-checkbox
[value]="element?.properties.value"
[disabled]="field?.properties.disabled"
[checked]="isItemChecked(element?.properties.value)"
(change)="onCheckboxChange(element?.properties.value);
notifyFormOfChange($event);">
{{element?.properties.title}}
</mat-checkbox>
</div>
</div>
There are two ways this can be displayed: 有两种显示方法:
1) HORIZONTAL 2) VERTICAL 1)水平2)垂直
Vertical ONLY occurs with a form-group where I have multiple checkboxes or radio buttons (which I need to fix as well). 垂直仅发生在一个表单组中,在该表单组中我有多个复选框或单选按钮(也需要修复)。 When I don't use a form-group and simply put checkboxes or radio buttons, I have a LINE of CBX's or RB's with no space between them.
当我不使用表单组而只是放置复选框或单选按钮时,我会有CBX或RB的行,它们之间没有空格。
I need to VERTICALLY stack the CHECKBOXES when this property is set to true: 当此属性设置为true时,我需要垂直堆叠CHECKBOXES:
field.properties.stackVertically = true
I can only do this with CSS. 我只能用CSS做到这一点。
Here's the CSS for the form-group 这是表单组的CSS
.row[_ngcontent-c30] {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;
}
And there's nothing like that for the HORIZONTAL. 水平仪没有什么比这更好的了。
Switch VERTICAL is an OPTION "IF" this 开关垂直是一个选项“如果”,这
field.properties.stackVertically = true
Here are the two pics of what I'm speaking of: 这是我在说的两张照片:
UPDATE TO THE GREAT ANSWER!!! 更新到伟大的答案!!!
See the SUCCESS image and here's the CODE from above with the solution integrated. 参见SUCCESS图像,这是集成了解决方案的上述CODE。
I have to place the SOLUTION in the SECOND line not where I thought it had to be. 我必须将解决方案放在第二行而不是我认为必须的位置。 A bit of Trial and Error but it works!!!
有点试验和错误,但有效!!!
Now here's the code from above with answer by KimCindy! 现在这是上面的代码,由KimCindy回答! Thank you!
谢谢!
<div *ngSwitchCase="'checkboxField'" class="checkbox-field">
***<div class="cb-wrapper" [ngClass]="{'cb-vertical': field?.properties?.stackVertically }">***
<div *ngIf="!field?.properties?.hideTitle">{{field?.properties.title}}</div>
<div class="checkbox-label" *ngFor="let
element of field?.elements">
<mat-checkbox
[value]="element?.properties.value"
[disabled]="field?.properties.disabled"
[checked]="isItemChecked(element?.properties.value)"
(change)="onCheckboxChange(element?.properties.value);
notifyFormOfChange($event);">
{{element?.properties.title}}
</mat-checkbox>
</div>
***</div>***
</div><!--checkbox-->
Maybe you could try the ngClass directive. 也许您可以尝试使用ngClass指令。
Kindly see below example: 请看下面的例子:
HTML: HTML:
<div class="cb-wrapper" [ngClass]="{'cb-vertival': !tmp }">
<mat-checkbox>Check 1</mat-checkbox>
<mat-checkbox>Check 2</mat-checkbox>
<mat-checkbox>Check 3</mat-checkbox>
<div>
CSS: CSS:
.cb-wrapper {
display: flex;
flex-wrap: wrap;
justify-content: left;
flex-flow: row;
}
.mat-checkbox {
margin-left:20px;
}
.cb-vertival {
flex-flow: column;
}
TS: TS:
export class CheckboxLayoutExample {
tmp : boolean = false;
}
Stackblitz: https://stackblitz.com/edit/angular-addm8z?file=app%2Fcheckbox-overview-example.css Stackblitz: https ://stackblitz.com/edit/angular-addm8z ? file = app%2Fcheckbox-overview-example.css
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.