Skip to content

Commit 8c75b5f

Browse files
keirpetebacondarwin
authored andcommitted
docs(compiler): fix variable scope in drag sample
Note that without this fix, if you add a second draggable element, the two instances clobber each other since there is only one set of startx/starty/x/y variables. Here is an example: http://plnkr.co/edit/aGrLXcIo2SuaePuAdfmQ?p=preview. On the surface it looks like it would be fine because you only have one mouse but in practice the start position jumps when you start dragging. Here it is fixed: http://plnkr.co/edit/VuvPasuumtCeiVRisYKQ?p=preview
1 parent 2d66ccd commit 8c75b5f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/content/guide/compiler.ngdoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ Here is a directive which makes any element draggable. Notice the `draggable` at
7070
<file name="script.js">
7171
angular.module('drag', []).
7272
directive('draggable', function($document) {
73-
var startX=0, startY=0, x = 0, y = 0;
7473
return function(scope, element, attr) {
74+
var startX = 0, startY = 0, x = 0, y = 0;
7575
element.css({
7676
position: 'relative',
7777
border: '1px solid red',

0 commit comments

Comments
 (0)