Angular $scope.form value undefined on submit in ionic

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this post i will show you angular $scope.from value undefined on submit in ionic. When i was learning first time in ionic framework with a search module. i was fetch one issue i can’t get ng-model value in angular js controller on submit form. On that time i was try like $scope.form because if we are working on angular JS before then we can get all post data by using $scope.form directly, But i was try with bellow form and also try to get on that way but i always find this is undefined value on form, But at last i was found how to solve this issue. We can see the bellow example and find our solution.

Form

<form method="POST" name="searchForm" ng-submit="search()">
  <div class="item item-input-inset">
    <label class="item item-input">
      <input ng-model="form.keyword" type="text" required>
    </label>
    <button class="button-calm" type="submit">
      <i class="icon ion-search"></i>
    </button>
  </div>
</form>

Controller

.controller('SearchCtrl', function($scope,$http) {
  $scope.posts = [];
  $scope.search=function(){
    var form = this.form;
    console.log(form);
    
    $http.post(url+'/api/get_search_post',form).success(function(items) {
          $scope.posts = $scope.posts.concat(items.data);
      });
  };
});

Read Also : Laravel import export to excel and csv using maatwebsite

Thanks for read. I hope it help you. For more you can follow us onĀ facebook.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →