0

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();
2
  • the jsfiddle you provided is broken Commented Oct 21, 2015 at 8:14
  • Yeah that is just to show the code, it depended on a few things to work which I haven't attached Commented Oct 21, 2015 at 8:23

1 Answer 1

1

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 = {};

Sign up to request clarification or add additional context in comments.

4 Comments

I'm doing form={} because the form scope variable is being passed in the submit function. I was getting confused about the scope so I thought that would be the most clear-cut way to get the right scope and do stuff with it.
how do I know whether it is in the digest cycle?
I've been literally banging my head against the wall but at the $scope.$apply(); did it. I thought $scope.$apply(); is only used when changes outside of angular are done or yeah outside of digest cycle. I don't know how to check if changes are in digest cycle or not.
Well, go read about how angular's digest cycle works. Basically, whatever, it keeps a watch on is in the digest cycle. Asynchronous requests is one example which are not in the digest cycle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.