显示复选框输入表格时出错

时间:2016-04-06 04:05:14

标签: javascript angularjs

我将此表显示为用户单击的复选框元素。但现在如果用户单击该复选框,它将不会显示任何内容。

<td ng-switch="user.scope">
   <span class="label label-primary" ng-switch-when="1">Admin</span>
   <span class="label label-primary" ng-switch-when="2">App</span>
   <span class="label label-primary" ng-switch-when="3">Redemption</span>
</td>

这是我的模态形式的复选框元素。

<label for="scope">Scope</label><br>
  <input type="checkbox" ng-model="user.scope.admin" name="scope[]" value="1"> Admin <br>
  <input type="checkbox" ng-model="user.scope.app" name="scope[]" value="2"> App <br>
  <input type="checkbox" ng-model="user.scope.redemption" name="scope[]" value="3"> Redemption <br>

这是javascript部分。

$scope.users = [{username: "a", name:"b", password:"c", confirmpassword:"d", status:"0", scope:"1" }];

    $scope.addUser = function(user) {
        $dialog.open({
            showClose: false,
            closeByEscape: true,
            template: 'views/user/user-user-add.html',
            controller: ['$scope', function ($dialogScope) {
                $dialogScope.isLoading =false;
                $dialogScope.title = "New User";
                $dialogScope.user = {
                    username : "" ,
                    name : "",
                    password :"",
                    confirmpassword :"",
                    status : "",
                    scope : {},
                };

 $dialogScope.add = function() {
                    console.log($dialogScope.user);
                    $scope.users.push($dialogScope.user);
                    $dialogScope.closeThisDialog();
                }

1 个答案:

答案 0 :(得分:0)

对于多重选择,您不能使用ng-switch,因为它只依赖于一个表达式的值,您需要检查每个表达式user.scope.admin等并使用ng-show。

示例:

<td>
   <span class="label label-primary" ng-show="user.scope.admin">Admin</span>
   <span class="label label-primary" ng-show="user.scope.app">App</span>
   <span class="label label-primary" ng-show="user.scope.redemption">Redemption</span>
</td>