我想将true
保存在是回答上,将false
保存在否:
<div layout-gt-sm="row">
Insured?
<md-radio-group ng-model="vehicle.insured">
<md-radio-button value="true" class="md-primary">Yes</md-radio-button>
<md-radio-button value="false"> No </md-radio-button>
</md-radio-group>
</div>
它将值保存在数据库中,但它不绑定现有值,因此当用户检索记录时没有选择的答案
答案 0 :(得分:9)
猜猜你的意思是初始化md-radio-group,尝试将value
替换为ng-value
。
var app = angular.module('angularMaterialApp', ['ngMaterial']);
app.controller('mainCtrl', ['$scope',
function($scope) {
$scope.vehicle = {
Insured: true
};
}
]);
&#13;
<html lang="en" ng-app="angularMaterialApp">
<head>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/angular_material/0.8.3/angular-material.min.css">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular-animate.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular-aria.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angular_material/0.8.3/angular-material.min.js"></script>
<script src='app.js'></script>
</head>
<body ng-controller="mainCtrl">
<p>Selected Value: <span class="radioValue">{{ vehicle.Insured }}</span>
</p>
<md-radio-group ng-model="vehicle.Insured">
<md-radio-button ng-value="true">Yes</md-radio-button>
<md-radio-button ng-value="false">No</md-radio-button>
</md-radio-group>
<hr />
</body>
</html>
&#13;