Saturday, October 21, 2017

ng-show doesn’t work correct with value boolean

I have one issue like that:

<input type="text" ng-model="keyword" ng-change="filterItemByName()">
<ul class="suggestion-list dropdown-menu" ng-show="isSearching">
  <li ng-repeat="item in list">
    <span ng-click="handleAction(item);"></span>
  </li>
</ul>

And here is the js:

$scope.isSearching = false;

$scope.filterItemByName = function(){
    //handle for searh item
    $scope.isSearching = true;
};

$scope.handleAction = function(item) {
    console.log(item);

    $scope.isSearching = false;
};

The problem in here is, when input the keywork, my app will call an request to get the list (suggestions), but when i click on the item in the list, nothing happend, it doesn’t log anything, it didn’t call handleAction as is.

I just found the problem related about the $scope.isSearching, when we show like above, the ng-click doesn’t trigger. But if i do :

<ul class="suggestion-list dropdown-menu" ng-show="isSearching == true">

It works fine. Anyone can explain for me that? Thanks.

Source: AngularJS



from Angular Questions https://angularquestions.com/2017/10/21/ng-show-doesnt-work-correct-with-value-boolean/
via @lzomedia #developer #freelance #web #lzomedia.com

No comments:

Post a Comment