Chronicle Different Scopes Example
HTML
<script src="https://rawgit.com/Blitzen/Angular-Chronicle/master/chronicle.js"></script>
<div ng-controller="ThisCtrl as TC">
<div ng-repeat="data in TC.num">
{{data}}
<button ng-click="TC.update(data)" >Update</button>
</div>
<button ng-click="TC.undo()" ng-show="TC.canUndo">Undo</button>
<button ng-click="TC.redo()" ng-show="TC.canRedo">Redo</button>
</div>
JavaScript
var myApp = angular.module('myApp',['Chronicle']);
myApp.controller('ThisCtrl', function(Chronicle) {
//variable initializtion
this.num = [{name:"chennai",values:{"Id":"1",city:"che"}},
{name:"Bangalore",values:{"Id":"2",city:"BLR"}}];
this.canUndo = false;
this.canRedo = false;
this.update=function(obj)
{
obj.name= obj.name+"1";
obj.values.Id= obj.values.Id+"1";
obj.values.city= obj.values.city+"1";
};
//Chronicle object creation
this.numChronicle = Chronicle.record('num', this);
this.canUndoRedo = function(){
this.canUndo = this.numChronicle.canUndo();
this.canRedo = this.numChronicle.canRedo();
}.bind(this);
this.numChronicle.addOnAdjustFunction(this.canUndoRedo);
this.numChronicle.addOnUndoFunction(this.canUndoRedo);
this.numChronicle.addOnRedoFunction(this.canUndoRedo);
//Functions called by buttons
this.increment1 = function(){
this.num++;
};
this.increment5 = function(){
this.num+= 5;
};
this.undo = function(){
this.numChronicle.undo()
};
this.redo = function(){
this.numChronicle.redo()
};
});