Angularjs 角度JS,在模型内部设置过滤器初始值
我想在Angular JS应用程序中设置一些过滤器复选框。我曾尝试使用Angularjs 角度JS,在模型内部设置过滤器初始值,angularjs,angularjs-scope,Angularjs,Angularjs Scope,我想在Angular JS应用程序中设置一些过滤器复选框。我曾尝试使用nginit和checked=true一起使用,但它没有像我预期的那样工作。我想将所有复选框设置为最初选中 我是个新手,但是我试着去寻找我想要的信息。因此,现在我确定我需要通过设置模型内部的值来设置“检查性”。所以(这是我完全错误的地方)我使用: $scope.location = ['rural', 'urban', 'coastal'] 使用如下复选框: <label><input type="che
nginit
和checked=true
一起使用,但它没有像我预期的那样工作。我想将所有复选框设置为最初选中
我是个新手,但是我试着去寻找我想要的信息。因此,现在我确定我需要通过设置模型内部的值来设置“检查性”。所以(这是我完全错误的地方)我使用:
$scope.location = ['rural', 'urban', 'coastal']
使用如下复选框:
<label><input type="checkbox" ng-model="location.rural" class="ng-valid ng-dirty">Rural</label>
<label><input type="checkbox" ng-model="location.urban" class="ng-pristine ng-valid">Urban</label>
<label><input type="checkbox" ng-model="location.coastal" class="ng-pristine ng-valid">Coastal</label>
<hr>
<label><input type="checkbox" ng-model="property_type.pub" class="ng-valid ng-dirty">pub</label>
<label><input type="checkbox" ng-model="property_type.bandb" class="ng-valid ng-dirty">bandb</label>
<label><input type="checkbox" ng-model="property_type.hotel" class="ng-valid ng-dirty">hotel</label>
})
如何在init上选中复选框?要开始使用ng model指令应该引用模型中的布尔值,而不是字符串。然后,您可以在控制器中将这些布尔值初始化为true或false:
propertyApp.controller('PhoneListCtrl', function ($scope) {
$scope.location = {
rural: true,
urban: true,
coastal: true
}
$scope.property_type = {
pub: true,
bandb: true,
hotel: true
}
});
也让我们来看看什么是原始的,什么是肮脏的
propertyApp.controller('PhoneListCtrl', function ($scope) {
$scope.location = {
rural: true,
urban: true,
coastal: true
}
$scope.property_type = {
pub: true,
bandb: true,
hotel: true
}
});