Angular $scope.form Value undefined on Submit in Ionic Framework
When i was working first time in ionic framework with search module. i fetch one issue i can't get ng-model value in angular js controller on submit form. i was try like $scope.form because if you work on angular JS before then you can get all post data using $scope.form directly, But i try with bellow form and try to get that way but i always find undefined value on form, But at last i found how to solve this issue. you can see bellow example and find your 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);
});
};
});
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Install Tailwind CSS in Angular?
- Angular Get Current Used Port Number Example
- Angular Material Select Option Group Example
- Angular Material Carousel Slider Example
- Angular Pipe for Phone Number Example
- Angular Material Input Autocomplete Example
- Angular Get Active Route URL Example
- Angular Get Parameters from URL Route Example
- How to Get Current URL in Angular?
- Angular Change Date Format in Component Example
- Reactive Form with Validation in Angular 8