如何在md-radio-button的角度上进行“检查”

时间:2021-01-13 13:43:37

I need to check an md-radio button. I saw on their website that they do it in scope in app.js but need to do it dynamically. I have tried with ng-checked but didn't work.

我需要检查一下md-单选按钮。我在他们的网站上看到他们在app.js中使用作用域,但是需要动态地使用它。我尝试过使用ng-check,但没有成功。

Is there any way to modify the javascript variable data of $scope to add the checked?

有什么方法可以修改$scope的javascript变量数据来添加选中的?

3 个解决方案

#1


2  

Init your controller's scope variable to the value you have in your md-radio-button defined.

将控制器的作用域变量初始化为md-radio-button定义的值。

In Controller:

控制器:

$scope.gender = 'male';

In template:

在模板:

<md-radio-button ng-model="gender" value="male">Male</md-radio-button>

Here male will be selected. You can change it even on some actions (click, ajax load, etc..), you just need to change the model value to the right value in order to have it selected.

这里将选择男性。您甚至可以在某些操作(单击、ajax load等)上更改它,您只需要将模型值更改为正确的值,以便选中它。

#2


0  

ng-checked is used to check only for checkbox type button to be used with
either-

ng-checked仅用于复选框类型按钮,用于与-和-

<input type="checkbox" name="gender" value="male" ng-checked="male"> Male

or

<md-checkbox value="male" ng-checked="male" aria-label="male"> Male </md-checkbox>

If you want to check a radio button as md-radio-button use ng-value instead of value without ng-checked="male" E.g.

如果你想检查一个单选按钮作为md-radio-button使用ng-value而不是没有ncheck的value ="male"例如:

<md-radio-group ng-model="gender">
    <md-radio-button ng-value="male" >mlae </md-radio-button>
    <md-radio-button ng-value="female" >female </md-radio-button>
</md-radio-group>

this code segment will model values of gender and male will be checked if previously gender = 'male'.

此代码段将对性别值进行建模,如果先前的性别= 'male'将被检查。

Hope this will help!

希望这将帮助!

#3


0  

I see that you need to load it from DB, try it, on you promise:

我看到你需要从DB上加载它,试试,对你的承诺:

promise.then( function (response) {
   $scope.yourVarHere = response.data.yourValueFromServer;
});

#1


2  

Init your controller's scope variable to the value you have in your md-radio-button defined.

将控制器的作用域变量初始化为md-radio-button定义的值。

In Controller:

控制器:

$scope.gender = 'male';

In template:

在模板:

<md-radio-button ng-model="gender" value="male">Male</md-radio-button>

Here male will be selected. You can change it even on some actions (click, ajax load, etc..), you just need to change the model value to the right value in order to have it selected.

这里将选择男性。您甚至可以在某些操作(单击、ajax load等)上更改它,您只需要将模型值更改为正确的值,以便选中它。

#2


0  

ng-checked is used to check only for checkbox type button to be used with
either-

ng-checked仅用于复选框类型按钮,用于与-和-

<input type="checkbox" name="gender" value="male" ng-checked="male"> Male

or

<md-checkbox value="male" ng-checked="male" aria-label="male"> Male </md-checkbox>

If you want to check a radio button as md-radio-button use ng-value instead of value without ng-checked="male" E.g.

如果你想检查一个单选按钮作为md-radio-button使用ng-value而不是没有ncheck的value ="male"例如:

<md-radio-group ng-model="gender">
    <md-radio-button ng-value="male" >mlae </md-radio-button>
    <md-radio-button ng-value="female" >female </md-radio-button>
</md-radio-group>

this code segment will model values of gender and male will be checked if previously gender = 'male'.

此代码段将对性别值进行建模,如果先前的性别= 'male'将被检查。

Hope this will help!

希望这将帮助!

#3


0  

I see that you need to load it from DB, try it, on you promise:

我看到你需要从DB上加载它,试试,对你的承诺:

promise.then( function (response) {
   $scope.yourVarHere = response.data.yourValueFromServer;
});