My setup is very simple
<button ng-click="query = ''" ng-if="query">X</button>
<input type="text" ng-model="query">
Check on planker but when I click on the button input is not cleaned
My setup is very simple
<button ng-click="query = ''" ng-if="query">X</button>
<input type="text" ng-model="query">
Check on planker but when I click on the button input is not cleaned
ng-if creates a child scope and the ng-click ="query=''" is set on child scope. Whereas your ng-model=query is defined on the parent scope.
The options are either to use ng-show
or pass a object property. See my fiddle here
http://plnkr.co/edit/LGmPALg4wTTmCJLE4aFa?p=preview
It would look like this
<body ng-app="" ng-init='query={data:""}'>
<button ng-click="query.data = 'a'" ng-if="query.data">X</button>
<input type="query" ng-model="query.data">
</body>
Also spend some time of understanding the prototype inheritance in angularjs scope https://github.com/angular/angular.js/wiki/Understanding-Scopes
$scope.query = '' for initialization. Because I need to have access to input value there. How it should be then?ng-show, but I still what to understand what is the difference.ng-click="query=''", you are setting a variable on the new scope, not the query property on parent scope. Look at the wiki and use batarang extension for chrome with your old example, you would see the scopes and the properties defined on it.