0

I use ng-repeat in my html file to display friend list in my chat application:

<input type="search" class="form-control app-search" placeholder="Search.." data-ng-model="search" />
        <div class="list-group-item media" href="#"  ng-repeat="friend in datauser['data']['friends'] | filter : {nama : search}"  data-ng-click="chatWith(friend.userid , friend.nama)" data-ng-class="(friend['ischat'] ? 'blokchat' :'')">
            <div class="pull-left">
                <i class="fa fa-user chat-user-avatar"></i>
            </div>
            <div class="media-body" >
                <h5 class="media-heading">{{friend.nama}} <span class="badge bg-danger" data-ng-if="friend['ischat']">*</span></h5>
            </div>
        </div>

the result from this code is like this: enter image description here

the total of friends for each users is different, so for user Tsalits, he has five friends. friends in this friend list is arranged by the time they become friend, so the newest friend will be on bottom of the list. and in the controller, I want to take the index value from user's friend list to use it in the speech recognition. the code for my speech recognition is:

$scope.recog = function() {
    var recognition = new SpeechRecognition();
    recognition.onresult = function(event) {
    var msg = 'Sorry, there is no such a command like that';
    var result = event.results[0][0].transcript;
        switch(result){
        case 'go to home':
        $location.path('/home');
            break;
        case 'go to add friend':
        $location.path('/addfriend');
            break;
        case 'go to friend request':
        $location.path('/friendrequest');
            break;
        case 'go to pending request':
        $location.path('/penddingrequest');
            break;
        case 'add':
        $scope.addfriends();
            break;
        case 'send':
        $scope.sendMessage();
            break;
        default:
        navigator.notification.alert(msg, '', 'Undefined Command!','ok');
        break;

    };
    $scope.$apply()
    };
    recognition.start();
  };

and I want use the length of index from friend list in speech recognition like this:

case 'chat with friend number ' + i:
  $scope.chatWith(friend.userid , friend.nama);
  break;

i in there is the number of index from user's friend list. from example from user Tsalits, if he want to chat with Ryan, he just said "chat with friend number 4".

the question is how do I take the length of Index from friend list to use it as i?

Khoirul Z
  • 75
  • 9

0 Answers0