AngularJS:默认情况下不会选中单选按钮

时间:2016-07-01 21:15:55

标签: javascript angularjs

我正在用角度编码一些单选按钮,但我不能让其中一个无线电出现标记为默认。 这是我的代码:

#box {
    background-color: #EEE;
    Width: 100px;
    Height: 100px;
}

容器是这样的:

<!-- language: lang-js -->

    //And this is the JavaSctipt:

    $scope.locationLookup = 1;
    $scope.updateDropdownValuesBreedingLocation = function() { // Change state for breeding
      // location radio
      $scope.dropdownValues = ($scope.localData.useFavorites) ? $scope.variableDefinition.possibleValuesFavorite : $scope.variableDefinition.possibleValues;
      $scope.locationLookup = 1;
    };

    $scope.updateDropdownValuesAllLocation = function() { // Change state for all locations radio
      $scope.dropdownValues = ($scope.localData.useFavorites) ? $scope.variableDefinition.allFavoriteValues : $scope.variableDefinition.allValues;
      $scope.locationLookup = 2;
    };

<!-- language: lang-html -->
<!-- show-setting-form-element-new.html  -->
    <div ng-switch="widgetType">
    <div ng-switch-when="DROPDOWN">
        <input type="hidden" ui-select2="dropdownOptions" class="form-control select2" ng-model="valuecontainer[targetkey]" value-as-object="false" ng-change="changefunction()" ng-disabled="blockInput"/>
        <div ng-if="isLocation">
            <div class="possibleValuesDiv">
                <input type="radio" ng-disabled="blockInput"
                 ng-model="locationLookup" value=1 ng-change="updateDropdownValuesBreedingLocation()"> &nbsp;
                <span th:text="#{show.breeding.location}">Breeding locations</span> &nbsp;
                <input type="radio" ng-disabled="blockInput" 
                ng-model="locationLookup" value=2 ng-change="updateDropdownValuesAllLocation()"> &nbsp;
                <span th:text="#{show.all.location}">All locations types</span>
            </div>
            <div class="possibleValuesDiv">            
                <input type="checkbox" ng-model="localData.useFavorites" ng-checked="true" ng-change="updateDropdownValuesFavorites()"> &nbsp;
                <span th:text="#{show.favorite.location}">Show only favorite locations </span> &nbsp;
            </div>
        </div>
        <div ng-if="isBreedingMethod" class="possibleValuesDiv">
            <!--TODO : handle rendering of breeding method dropdowns for completeness-->
        </div>
    </div>
    <div ng-switch-when="NTEXT">
        <input type="text" ng-disabled="blockInput" valid-decimal="" class="form-control numeric-input" ng-model="valuecontainer[targetkey]" ng-change="changefunction()"/>
    </div>
    <div ng-switch-when="SLIDER">
        <input type="text" ng-disabled="blockInput" valid-decimal="" class="form-control numeric-input" ng-model="valuecontainer[targetkey]" ng-change="changefunction()"/>
    </div>
    <div ng-switch-when="CTEXT">
        <input type="text" ng-disabled="blockInput" class="form-control character-input" ng-model="valuecontainer[targetkey]" ng-change="changefunction()"/>
    </div>
    <div ng-switch-when="TEXTAREA">
        <textarea ng-disabled="blockInput" class="form-control character-input" rows="3" ng-model="valuecontainer[targetkey]" ng-change="changefunction()"/>
    </div>
    <div ng-switch-when="DATE">
        <input type="text" ng-disabled="blockInput" placeholder="yyyy-mm-dd" class="form-control date-input" ng-model="valuecontainer[targetkey]" jq-datepicker="true" with-image="true" image-src="/Fieldbook/static/img/calendar.png" ng-change="changefunction()"/>
    </div>
</div>

<!-- end snippet -->
你能帮帮我吗? 最有趣的是,如果我把这些无线电放在桌子外面,它工作正常!但不在里面。

0 个答案:

没有答案