AngularJS niether ng-keypress or custom directive are working -
trying implement simple keypress event on div somehow nothing happens. have read @ places need tabindex="0"
, problem still prevails. here html:
<body ng-app="mymodule"> <div ng-controller="myctrl" movement tabindex="1" ng-keypress="iterate($event)"> <div ng-repeat="entity in entities" entity-position="entity"></div> <div class="table"> <div> <select selected='name' ng-model="selected" id="select"> <option value="name" >first</option> <option value="id">second</option> <option value="id">third</option> </select> </div> <table id="table"> <tr ng-repeat="item in cars | orderby:selected" ng-click="go(item)"> <td>{{item.plate}}</td> <td>{{item.name}}</td> <td>{item.price}}</td> </tr> </table> </div>
"movement" custom directive it's own controller, i'm guessing problem connected this, i'm not sure.
this inside movement directive's controller (never logs anything):
$scope.iterate = function($event){ console.log('iterate') }
thank help.
edit: added directive
app.directive('movement', function() { return { controller: function($scope, animframe) { var width = window.innerwidth; var height = window.innerheight; var speed = .5; var lasttime = new date().gettime(); $scope.entities = []; $scope.changecount = function(count) { while(count>0) { $scope.entities.push({ x: width/2 * math.random()+100, y: height/2 * math.random()+100, velx: 0.2,//speed * math.random()/2, vely: 0.1,//speed * math.random()/3 }); count--; } while(count<0) { $scope.entities.pop(); count++; } } $scope.tick = function($event){ //console.log('tick') var = new date().gettime(), delay = - lasttime, entities = $scope.entities; for(var i=0; i<entities.length; i++) { var b = entities[i]; b.x += delay * b.velx; b.y += delay * b.vely; if (b.x < 0) { b.x *= -1; b.velx *= -1;} if (b.y < 0) { b.y *= -1; b.vely *= -1; } if (b.x > width) { b.x = 2*width - b.x; b.velx *= -1;} if (b.y > height) { b.y = 2*height - b.y; b.vely *= -1; } } lasttime = now; animframe($scope.tick); } $scope.changecount(1); $scope.tick(); } }; });
Comments
Post a Comment