Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align the radio buttons horizontally in angular material?

I was expecting a in-built directive or a tag for this but probably not according to their documentation.

This is the example.

<div class="radioButtondemoBasicUsage" ng-app="MyApp"> <form ng-submit="submit()" ng-controller="AppCtrl"> <p>Selected Value: <span class="radioValue">{{ data.group1 }}</span> </p>  <md-radio-group ng-model="data.group1">    <md-radio-button value="Apple" class="md-primary">Apple</md-radio-button>   <md-radio-button value="Banana"> Banana </md-radio-button>   <md-radio-button value="Mango">Mango</md-radio-button>  </md-radio-group> 

like image 268
Asqan Avatar asked Jun 29 '15 11:06

Asqan


People also ask

What is a radio button in Angular 2?

Angular Radio Button The <mat-radio-button> provides the same functionality as a native <input type=”radio”> enhanced with Material Design styling and animations. In the radio button, the user can only select one value at a time; that is why radio-buttons with the same name comprise a set from which the only one may be selected at one time.

How to get input radio elements to horizontally align in react material?

To get input radio elements to horizontally align in React Material UI, we can add the row prop to the RadioGroup component.

What is a radio group in angular?

The radio group has the value property that reflects the currently selected radio button inside of the group. Individual radio buttons inside of the radio group will inherit the name of the group. The <mat-radio-group> is compatible with @angular/forms and supports both FormsModule and ReactiveFormsModule.

Which components are generally used using Angular Material?

Components such as autocomplete, date picker, slider, menus, grids, toolbars, and radio buttons are generally used using Angular Material. A radio button is a simple input element with a type property set to radio.


2 Answers

You do not need to override any default CSS:

<md-radio-group layout="row">   <md-radio-button value=0 class="md-primary">On</md-radio-button>   <md-radio-button value=1> Off </md-radio-button> </md-radio-group> 

enter image description here

Just put in md-radio-group tag a layout="row" attribute.

like image 88
Fábio Palmeira Avatar answered Oct 09 '22 23:10

Fábio Palmeira


Better not override any existing class.

Use the directive ng-style and give value for display parameter.

<md-radio-group ng-model="selvalue">   <md-radio-button value="A" class="md-primary" ng-style="{'display':'inline'}"> Apple</md-radio-button>   <md-radio-button value="R" class="md-primary" ng-style="{'display':'inline'}"> Orange </md-radio-button> </md-radio-group> 
like image 22
Shyam Devasia Avatar answered Oct 10 '22 00:10

Shyam Devasia