From de5352cfcfa3705bb2ea9f1ca4ee71a2ce18ceb5 Mon Sep 17 00:00:00 2001 From: Keir Mierle Date: Sun, 21 Apr 2013 16:37:53 -0700 Subject: 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 --- docs/content/guide/compiler.ngdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/content/guide/compiler.ngdoc') diff --git a/docs/content/guide/compiler.ngdoc b/docs/content/guide/compiler.ngdoc index 9915107b..d315df45 100644 --- a/docs/content/guide/compiler.ngdoc +++ b/docs/content/guide/compiler.ngdoc @@ -70,8 +70,8 @@ Here is a directive which makes any element draggable. Notice the `draggable` at angular.module('drag', []). directive('draggable', function($document) { - var startX=0, startY=0, x = 0, y = 0; return function(scope, element, attr) { + var startX = 0, startY = 0, x = 0, y = 0; element.css({ position: 'relative', border: '1px solid red', -- cgit v1.2.3