jeudi 30 juin 2016

how to make checkbox checked by default in angularjs

I have two address fields. If current address is same as permanent address user will select checkbox then the value from current address field will be copied to permanent address field and permanent address field will gets disabled automatically.

But my issue is when i refresh the page or logout and login again then the checkbox become unchecked so the permanent address field become enable.

HTML :

<div class="form-group col-sm-6" ng-class="{ 'has-error': pForm.caddress.$dirty && pForm.caddress.$error.required }">                          
                                    <label class="control-label l_font" for="address">Current Address*</label>
                                    <textarea class="form-control" type="text" name="caddress" placeholder="Current address" ng-model="caddress" ng-disabled ="!pEditMode"  ng-required = "true" ></textarea>
                                    <span ng-show="pForm.caddress.$dirty && pForm.caddress.$error.required" class="help-block">Current Address is required</span>                                
                                </div>


                                <div class="form-group col-sm-6" ng-class="{ 'has-error': pForm.paddress.$dirty && pForm.paddress.$error.required }">
                                    <label class="control-label l_font" for="address">Permanent Address*</label>
                                       <input type="checkbox" ng-model="sameAddrres" ng-checked="copyAddress()" ng-disabled ="!pEditMode" />
                                    <i class="inside">Select if Permanent address is same as Current address</i>

                                    <style>
                                    .inside 
                                        {
                                            font-size: 12px;
                                        }
                                    </style>
                                    <textarea class="form-control" type="text" name="paddress" placeholder="Permanent address" 
                                              ng-model="paddress" ng-disabled ="!pEditMode || sameAddrres" ng-required = "true" ></textarea>
                                    <span ng-show="pForm.paddress.$dirty && pForm.paddress.$error.required" class="help-block">Permanent Address is required</span>
                                </div>

Controller :

$scope.copyAddress = function(){

            if($scope.sameAddrres == true){

                $scope.paddress = $scope.caddress;
            }            
        };

can anyone please help me its very urgent.




Aucun commentaire:

Enregistrer un commentaire