Reputation: 35
i got some new issues in my spa with angularjs.
THIS ist my HTML:
<a ng-repeat="friend in chat.friendlist" ng-click="loadChat('{{friend.friend_username}}')" data-toggle="modal" data-target="#chat" data-dismiss="modal" class="list-group-item p-x-md">
<i class="fa fa-circle text-success text-xs m-r-xs"></i>
<span>{{friend.friend_username}} - {{friend.gamename}}</span>
</a>
This is my controller:
"use strict";
app.controller("chatCtrl", ["userService", "socket" , "chatService", "$scope", function (userService, socket , chatService, $scope) {
var self = this;
self.friendlist = chatService.friendlist;
chatService.init(userService.username);
$scope.loadChat = function (username) {
console.log(username); //console logs {{friend.friend_username}}
chatService.chatWith(username);
}
}]);
Everything is working properly except the username within the loadChat function. The username console logs {{friend.friend_username}} and not the value of friend.friend_username as i want to do. Within the DOM everything looks fine. ng-click="loadChat('USERNAME')" is shown properly but in chat controller the username is set as {{friend.friend_username}}. I´ve no clue why this happens. I hope someone can help me to figure this out.
Upvotes: 0
Views: 53
Reputation: 133453
Directly pass the user name to ngClick
, Don't use string interpolation
<a ng-click="loadChat(friend.friend_username)" >
Upvotes: 1