This seem a stupid questions. In IONIC Framework (ionicframework.com), How do we catch an event on textbox when its value changed ? (Don't use javascript built-in statement or jQuery support, user Ionic Framework only )
This is what I tried:
<input type="search" placeholder="Search" ng-text-change="searchMenu()">
And the controller.
....
// Tìm menu
$scope.searchMenu = function () {
alert('dsa')
console.log(1);
};
...
When I type on the text box,but nothing happens
It's ng-change not ng-text-change and you must have ng-model on that input element to trigger ng-change event
You need to add an ng-model
attribute and use ng-change
instead of ng-text-change
.
ng-change
is a built-in angular directive which fires events when the binded model (ng-model
) changes. ngChange documenation
So your html would be like:
<input ng-model="inputValue" ng-change="searchMenu" type="search" placeholder="Search">
In your controller, you need to add a $scope variable like:
$scope.inputValue = ''
There are two ways you can do that with ionic( which is angular in a nutshell)
$scope.$watch
:markup:
<input type="search" placeholder="Search" ng-model="search" />
and code:
$scope.$watch('search',function (oldValue, newValue) {
alert('dsa')
console.log(1);
};
ng-change
directive togher with ng-model
:markup:
<input type="search" placeholder="Search" ng-model="search" ng-change="onSearchChange" />
and code:
$scope.onSearchChange = function () {
alert('dsa')
console.log(1);
}