我希望在init上有一个选中的复选框。这是我的HTML:
<form ng-submit="submit()" name="orderForm" novalidate>
<input type="radio" id="service-professional" name="service-type" value="Professional" class="service-input" ng-model="orderForm.serviceType" ng-change="setService(value)" />
<input type="radio" id="service-premium" name="service-type" value="Premium" class="service-input" ng-model="orderForm.serviceType" ng-change="setService(value)" />
</form>
我的控制员:
// initializes the form
$scope.orderForm = {};
$scope.orderForm.serviceType = {
// how to set Premium as default?
};
我在$scope.orderForm.serviceType
尝试了很多东西,但是为了我,我无法弄明白。
您能解释一下如何将Premium设置为默认选中选项吗?谢谢!
答案 0 :(得分:0)
试试这个:
from tastypie.serializers import Serializer
...
class Meta:
queryset = Order.objects.all()
resource_name = 'order_status'
authorization = Authorization()
fields = ['id','status']
serializer = Serializer(formats=['json',])
list_allowed_methods = ['put',]
detail_allowed_methods = ['put',]
filtering = {
"id": ALL,
}
答案 1 :(得分:0)
以下内容应该有效:
// initializes the form
$scope.orderForm = {};
$scope.orderForm.serviceType = 'Premium';
答案 2 :(得分:0)
您只需使用此 - &gt;
ng-checked =&#34; your_model ==&#39;您的价值&#39;&#34; ,
<input type="radio" id="service-professional" name="service-type" ng-true-value="1" value="Professional" ng-false-value="0" ng-checked="orderForm.serviceType == 'Professional'" class="service-input" ng-model="orderForm.serviceType" ng-change="setService(value)" />
<input type="radio" id="service-premium" ng-true-value="1" ng-false-value="0" ng-checked="orderForm.serviceType == 'Premium'" name="service-type" value="Premium" class="service-input" ng-model="orderForm.serviceType" ng-change="setService(value)" />
答案 3 :(得分:0)
您需要使用 ng-init 为复选框范围设置默认值 例如:在html中添加 ng-init =“scopeName ='value'”,而不是在复选框ng-model中使用 scopeName 以及ng-checked
见下面的代码
<form ng-submit="submit()" name="orderForm" novalidate ng-init="orderForm.serviceType="1">
<input type="checkbox" id="service-professional" name="service-type" value="Professional" class="service-input" ng-model="orderForm.serviceType" ng-change="setService(value)" />
<input type="checkbox" id="service-premium" name="service-type" value="Premium" class="service-input" ng-model="orderForm.serviceType" ng-change="setService(value)" />
</form>