1

我有用戶的天選項。推送複選框值與多個ng模型

我預期的輸出將是,當用戶如果週一和週二,如果平日裏選擇應該是字符串'weekdays'

我選擇它應該是[1,2]

  • 點擊提交

    • 在這裏有太多的限制,因爲api嵌套很大,所以我更喜歡硬編碼天數值。但我不知道如何繼續下去。我能想到的唯一方法是爲每個輸入分配模型並進行推送,但我認爲這不合適。

      http://plnkr.co/edit/NfTgmsuZlGh6QUVZj8HG?p=preview

      需要幫助。

  • +0

    你可以使用ng-switch嗎? – HoKy22

    +0

    https://docs.angularjs.org/api/ng/directive/ngSwitch – HoKy22

    回答

    1

    您可以用這種方式嘗試也 在控制器

    $scope.items = [{"day":"monday","show":"1"},{"day":"tuesday","show":"2"},{"day":"weekdays","show":"weekdays"}]; 
    

    在HTML

    <select ng-model="selection" ng-options="item.show as item.day for item in items"> 
        <option value="">Please select</option> 
    </select> 
    

    輸出:{{選擇}}

    0

    試試這個方法:

    <div class="days-group" ng-repeat="timeType in timeTypes"> 
        <input type="checkbox" id="Weekdays" value="weekdays" ng-model="timeType.isSelected" ng-checked="timeType.isSelected"> 
        <label for="Weekdays">{{timeType.type}}</label> 
    </div> 
    

    controller

    $scope.timeTypes = [ 
            { id: 1, type: "weekends", isSelected: false }, 
            { id: 2, type: "weekdays", isSelected: false } 
            ]; 
    

    同樣的天也。

    檢查工作jsfiddle鏈接:

    https://jsfiddle.net/avnesh2/oho7qxv1/ 
    

    檢查console所需的格式。

    乾杯。