ng-model 在这里设置,所以我可以将过滤器传递到我的函数中并获得所有用户选择。我想我也可以用它来预填充/默认数据。它不工作。这是我的 Controller :
.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-model docs ,
The value to which the ngModel expression should be set when selected. Note that value only supports string values, i.e. the scope model needs to be a string, too. Use ngValue if you need complex models (number, object, ...).
关于javascript - angularjs - ng-model 没有为我设置默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35134917/