user3677331
user3677331

Reputation: 698

AngularJS form not resetting

I've been trying so hard to make this work. I know about child scopes and prototypal inheritance and I'm also using the dot notation for the model but I can't get the form to reset. Please check my form hosted here. The code is here Please help me reset the form scope variable. This is how I'm doing it currently

                            if(data==1){
                            if($scope.form.language=='English'){
                                toastr.success('Form has been submitted successfully', 'Success');
                            }
                            else{
                                toastr.success('הטופס נקלט בהצלחה', 'הצלחה');
                            }
                            form={};
                            console.log('Empty is'+empty);
                        }

I can't figure out what I'm doing wrong. And here's how I initialize my form variable.

        .controller('formCtrl', function($scope,$location,$translate,$filter) {
        $scope.form={};
        $scope.currentLang='en';
        $scope.form.createdate=new Date();

Upvotes: 0

Views: 43

Answers (1)

Tarun Dugar
Tarun Dugar

Reputation: 8971

Change form={}; to $scope.form = {};

Also, since you haven't provided the context of your code snippet (i.e whether its in the angular digest cycle), if the form doesn't reset add $scope.$apply(); just after $scope.form = {};

Upvotes: 1

Related Questions