当ng-click时,angularjs ng-show不起作用

时间:2016-04-19 08:42:42

标签: angularjs

<div role="tabpanel" class="tab-pane active" id="personnes">
    <div infinite-scroll='RedditUsers.nextPage()' infinite-scroll-disabled='RedditUsers.busy' infinite-scroll-distance='3'  >
        <div class="search-item row" ng-init="request=false" ng-repeat="user in RedditUsers.users" >
            <div class=" pull-left">
                <img ng-src="{{notif.subscriber.avatar == 'no_avatar' &&  '/images/default.svg' || 'http://localhost:85/api.immortality.life/application/uploads/avatars/'+user.id_user+'/'+user.avatar }}" class="edit-img">
                <span>{{user.first_name+' '+user.last_name}}</span>
            </div>
            <div class="pull-right" >


                <button ng-if="user.friend == null && request==false" ng-hide="request" ng-click="addFriend($event,user);request=true;" class="add-btn btn"><i class=" icon-friends s"></i>Ajouter</button>
                <span  ng-show="request" class="add-btn btn"><i class=" icon-friends s"></i>Demande envoyée</span>
                <span ng-if="user.friend != null " class="add-btn btn"><i class=" icon-friends s"></i></span>

            </div>
        </div>
        <div ng-show='RedditUsers.busy'>Loading data...</div>
    </div>
</div>

问题是,当我点击按钮时,第一个跨度不显示尽管我做了ng-show =&#34;请求&#34;

1 个答案:

答案 0 :(得分:0)

将ng-click更改为:

ng-click="addFriend($event,user);setRequest(true);"

在你的JS文件中

$scope.setRequest = setRequest;
function setRequest(val){
    $scope.request = val;
}