Search code examples
angularjsdirpagination

getting form undefiend in angularjs


I am creating web app using angularjs. I have integrate the dirPaginate directive for pagination.I am paginate the forms, Pagination works fine.When I submit the form first time.Form submit Succesfully. When I click on next number on pagiantion list and submit form again it says form is undefiend.

Here is Form:

var form = amazon.form; // first time works, after paginate gives undefiend
        $rootScope.amazonForm = form;

        // Show error messages and exit.
        if (form.$invalid) {
            if (form.$pristine) {
                form.$setDirty();
            }
         }

Solution

  • You can watch the form and can save the form to $scope

    $scope.$watch('amazon.form', function(amazonForm) {
         if(amazonForm) { 
          $scope.amazonForm = amazonForm;
         }
     });
    

    then can use below code in your function

    $scope.amazon.form = $scope.amazonForm;
    
    var form = $scope.amazon.form;