您好我在Ionic v1开发的聊天应用程序页面中有用户列表。
<div class="user-names">
<div class="card hovercard" ng-controller="CommunicationController" ng-repeat="person in allUsers">
<div class="ufor-pname">
<button title= "{{person.name}}" id="firstUser" value="{{person.name}}" class="button button-dark fuser-btn all-time-fix" ng-click = "getChat('{{person.id}}','{{person.name}}','{{LoggedInUserId}}')">
<img class="img-circle-main img-user" src="http://{{person.image}}" width="50px" height="50px">
</button>
<span class="user1-name"> {{person.name}} </span>
</div>
</div>
</div>
我想添加活动类,而用户将点击那里给出的列表中的任何用户。
//Controller
$scope.getChat = function (userIdFrom,messageFromName,LoggedInUserId) {
$rootScope.userIdFrom = userIdFrom;
$ionicLoading.show();
}
任何帮助将不胜感激。
谢谢你。
答案 0 :(得分:1)
在您的HTML中添加 data-ng-style =“getStyle(person.id)”,如下所示
<div class="user-names">
<div class="card hovercard" ng-controller="CommunicationController" ng-repeat="person in allUsers">
<div class="ufor-pname" data-ng-style="getStyle(person.id)">
<button title= "{{person.name}}" id="firstUser" value="{{person.name}}" class="button button-dark fuser-btn all-time-fix" ng-click = "getChat('{{person.id}}','{{person.name}}','{{LoggedInUserId}}')">
<img class="img-circle-main img-user" src="http://{{person.image}}" width="50px" height="50px">
</button>
<span class="user1-name"> {{person.name}} </span>
</div>
</div>
</div>
在JS代码中为 getStyle(); 添加一个函数,以返回所选人员ID的背景颜色。
//Function for set bakground color .
$scope.getStyle = function(person) {
$scope.Style = '';
if ($rootScope.userIdFrom == person) {
$scope.Style = '#F8F7D9';
}
return {'background-color': $scope.Style};
}
$scope.getChat = function (userIdFrom, messageFromName, LoggedInUserId) {
$rootScope.userIdFrom = userIdFrom;
$ionicLoading.show();
}