码迷,mamicode.com
首页 > 其他好文 > 详细

angular checkbox required

时间:2014-10-19 14:11:53      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   for   sp   div   

Here is the fiddle http://jsfiddle.net/lumixraku/xgLz7d4j/2/

html

<body ng-app="app">
    <div ng-controller=‘controller‘>
        <ng-form name="formName">
            <input type="text" ng-model="val1" required/>
            <div ng-show="myForm.items" ng-repeat="item in myForm.items">
                <label>
                    <input type="checkbox" name="group[]" ng-model="$parent.selectedValue[item.id]" value="{{item.id}}" ng-required="!someSelected($parent.selectedValue)" />{{item.sId}}</label>
            </div>{{selectedValue}}
            <input type="submit" ng-disabled="formName.$invalid">
                {{formName.$invalid}}
        </ng-form >
    </div>
</body>

JS

app = angular.module(‘app‘, []);

app.controller(‘controller‘, function ($scope) {
    $scope.myForm = {};
    $scope.selectedValue = {};
    $scope.myForm.items = [{
        id: 1,
        sId: "analog"
    }, {
        id: 2,
        sId: "isdn"

    }, {
        id: 3,
        sId: "dsl"
    }];
    $scope.someSelected = function (obj) {
        console.log(‘some selecgted‘);
        var rs=Object.keys(obj).some(function (key) {
            return obj[key];
        });
        console.log(rs);
        return rs;
    }
    $scope.submitForm = function(){
        $scope.clickSubmit = ‘clickSubmit‘;
    }

});

 

angular checkbox required

标签:style   blog   http   color   io   ar   for   sp   div   

原文地址:http://www.cnblogs.com/cart55free99/p/4034817.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!