ng-model 是在这里设置的,所以我可以将过滤器传递到我的函数中并获取所有用户的选择。 我想我也可以使用它来预填充/默认数据。 它不起作用。 这是我的控制器:
.controller('ListCtrl', [
'$scope', '$filter', '$location', 'context', 'breeze', 'Service',
function ($scope, $filter, $location, context, breeze, Service) {
$scope.pageLoaded = true;
$scope.lists = [];
$scope.DDL1 = '';
$scope.filter = {
fromDate: '2015-05-01',
toDate: '',
sales: false
};
我有这样的 html:
<md-content ng-controller="ListCtrl" layout="column" flex class="md-padding">
<md-tabs class="md-primary clearfix" md-selected="0" flex>
<md-tab label="Lists">
<table><tr>
<td width="10%">From Date: </td>
<td width="40%"><input type="date" ng-model="filter.fromDate" value="{{filter.fromDate}}"/></td>
<td width="10%">SParts: </td>
<td width="40%">
<input type="radio" name="sales" ng-model="filter.sales" value="true"> yes
<input type="radio" name="sales" ng-model="filter.sales" value="false" checked> no
</td>...
使用字符串
由于您使用 input type="radio"
,将filter.sales
的类型设置为字符串,这应该可以工作
$scope.filter = {
fromDate: '2015-05-01',
toDate: '',
sales: 'false'
};
<小时 />从input type="radio"
ng模型文档中,
选择时应将 ngModel 表达式设置为的值。请注意,值仅支持字符串值,即范围模型也需要是一个字符串。如果需要复杂模型,请使用 ngValue。(数字、对象等)。
您可以使用 ng-checked 的 angularjs 根据其他值预填充单选按钮。
例如:
<td width="40%">
<input type="radio" name="sales" ng-model=vm.filter.sales > yes
<input type="radio" name="sales" ng-model=vm.filter.sales ng-checked="true"> no
</td>
在上面的例子中,我直接将 ng-check 值设置为 true,但您也可以使用控制器变量将其设置为 true 或 false。有关更多信息,您可以查看文档@https://docs.angularjs.org/api/ng/directive/ngChecked