i have a variable workingIdx that needs to be updated to the id the div it is clicked on. It updates but when i query it again, it does not show new value.
My service:
writingPage.service('Lctr', function() {
this.workingIdx = 0;
return {
getWorkingIdx: this.workingIdx,
setWorkingIdx: function(i) {
this.workingIdx = i;
console.log("wIdx="+this.workingIdx);
}
};
});
My Controller where i am doing the updating and checking...
writingPage.controller('DataController' , ['SnippetPojo','$scope', '$timeout', 'Lctr', function(SnippetPojo, $scope, $timeout, Lctr) {
$scope.currDispLine = '';
$scope.myId = -1;
$scope.localCursor = 0;
$scope.hideOrShow = function(id, currentDivCursor) {
if(id <= currentDivCursor)
{
console.log("wIdx="+Lctr.getWorkingIdx+ " id="+id);
return false;
}
else
{
return true;
}
}
$scope.click = function(id) {
$scope.myId = id;
Lctr.setWorkingIdx($scope.myId);
console.log('MyId='+$scope.myId);
}
$('div').on( "keypress", function( event ) {
console.log("Event="+event.keyCode + " : "+event.which);
code = (event.keyCode ? event.keyCode : event.which);
if ( (code == 37 || code == 39) && event.shiftKey == true)
{
$timeout(function() {console.log('Selection set= ' +window.getSelection()); return false;}, 2200);
}
if ( code == 13) {
console.log("ENTERed ID="+$scope.myId + " wIdxOLD = "+ Lctr.getWorkingIdx);
if(Lctr.getWorkingIdx == $scope.myId) {
Lctr.setWorkingIdx(Number(Lctr.getWorkingIdx) +1);
localCursor = (Number(Lctr.getWorkingIdx) +1);
console.log("ENTERed ID="+$scope.myId + " wIdxNEW = "+ Lctr.getWorkingIdx);
$('#'+$scope.myId).blur();
$('#'+(Number(Lctr.getWorkingIdx) +1)).mousedown();
return false;
}
}
});
}]);
}
Finally the HTML
<div id='repeater' data-ng-controller='RepeatController'>
<!--<data-ng-div-line data-ng-repeat="div in divs track by $index" id="{{$index}}"></data-ng-div-line>-->
<div data-ng-repeat="div in divs track by $index" id="{{div}}" data-ng-controller='DataController' data-ng-click='click(div)' contenteditable="true" class="writediv" data-ng-model="localCursor" data-ng-mouseover="setId(div)" data-ng-show="!hideOrShow(div, localCursor)" data-ng-hide="hideOrShow(div, localCursor)"></div>
</div>
I see wIdx=1 set when i click the DIV and then the ENTERed ID=0 wIdxNEW = 0 displayed when i press enter in the DIV,