(function(){
    'use strict';
    app.controller('Edit',['$scope','$rootScope', function($scope, $rootScope){
        
        $rootScope.$on('EditComment', function(evnt, comments, id){
            for (let i = 0; i < comments.length; i++) {
                if(comments[i].id === id){
                    $scope.editCommetById = comments[i]
                }
                
            }
        })
        $scope.saveEdit = function(){
            $rootScope.$emit('saveEdit', $scope.editCommetById, $scope.editCommetById.id);
        }
        $scope.cancelEdit = function(){
            $rootScope.$emit('cancelEdit', $scope.editCommetById.id);
        }
        
    }])
})()