here is the fiddle: http://jsfiddle.net/paska27/L6VAe/5/
the code (so complains otherwise):
<div ng-app ng-controller="MainCtrl"
ng-init="list = [
{name: 'Sergey', age: 26},
{name: 'Johan', age: 27},
{name: 'Iwan', age: 28}
];">
<div id="box" ng-controller="PlaneCtrl"></div>
<input ng-model="currentItem.name" />
</div>
/** an extention of Kinetic shape (group, rect or what ever) **/
var Item = function(planeScope, item){
Kinetic.Group.call(this, {
draggable: true
});
var self = this;
var text = new Kinetic.Text({
x: 0,
y: 0,
text: item.name,
fontSize: 20,
fontFamily: 'Calibri',
textFill: 'green',
draggable: true
});
self.add(text);
self.name = text.getText();
self.on('dragstart', function(){
planeScope.$parent.currentItem = self;
planeScope.$apply();
});
}
Kinetic.Global.extend(Item, Kinetic.Group);
var MainCtrl = function($scope){
$scope.currentItem;
}
var PlaneCtrl = function($scope, $element){
var stage = new Kinetic.Stage({
container: 'box',
width: 200,
height: 200
}),
layer = new Kinetic.Layer();
angular.forEach($scope.list, function(item){
item = new Item($scope, item);
layer.add(item);
});
stage.add(layer);
}
The task:
The question in general: how to build all this ?
The particular stuck in the realization i chose: how to make a veiw --> model values update. or in terms of the the libs in question: how to update shapes properties (e.g. text of the Kinetic.Text obj) from the ng-model directive ?
Many thanks in advance !
This should be fairly straightforward to achieve using a custom chart directive. You can bind the items
to the directive which then creates a canvas instance and renders your chart. Binding items
to the directive will cause it to refresh every time the items
data changes or vice versa.
To create the canvas instance simply initiate that part within the link function of the directive. i.e. pretty much all the code you have right now can be added to the link function. Just make sure you are passing the items
object to the directive.
I show an example here of something similar using three.js
: AngularJS Binding to WebGL / Canvas