Skip to content

Commit 0215010

Browse files
author
Allen Kim
committed
Issue allenhwkim#291, removed observe restriction on ng-repeat
1 parent 25f840c commit 0215010

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

services/attr2_options.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
} catch(e) { // if not parsable, change little
2727
return str
2828
// wrap keys without quote with valid double quote
29-
.replace(/([\$\w]+)\s*:/g, function(_, $1){return '"'+$1+'":'})
29+
.replace(/([\$\w]+)\s*:/g, function(_, $1){return '"'+$1+'":';})
3030
// replacing single quote wrapped ones to double quote
31-
.replace(/'([^']+)'/g, function(_, $1){return '"'+$1+'"'})
31+
.replace(/'([^']+)'/g, function(_, $1){return '"'+$1+'"';});
3232
}
3333
}
3434

35-
var Attr2Options = function($parse, $timeout, NavigatorGeolocation, GeoCoder) {
35+
var Attr2Options = function($parse, $timeout, $log, NavigatorGeolocation, GeoCoder) {
3636

3737
/**
3838
* Returns the attributes of an element as hash
@@ -128,14 +128,13 @@
128128
var getAttrsToObserve = function(attrs) {
129129
var attrsToObserve = [];
130130
if (attrs["ng-repeat"] || attrs.ngRepeat) { // if element is created by ng-repeat, don't observe any
131-
void(0);
132-
} else {
133-
for (var attrName in attrs) {
134-
var attrValue = attrs[attrName];
135-
if (attrValue && attrValue.match(/\{\{.*\}\}/)) { // if attr value is {{..}}
136-
console.log('setting attribute to observe', attrName, camelCase(attrName), attrValue);
137-
attrsToObserve.push(camelCase(attrName));
138-
}
131+
$log.warn("It is NOT ideal to have many observers or watcher with ng-repeat. Please use it with your own risk");
132+
}
133+
for (var attrName in attrs) {
134+
var attrValue = attrs[attrName];
135+
if (attrValue && attrValue.match(/\{\{.*\}\}/)) { // if attr value is {{..}}
136+
console.log('setting attribute to observe', attrName, camelCase(attrName), attrValue);
137+
attrsToObserve.push(camelCase(attrName));
139138
}
140139
}
141140
return attrsToObserve;
@@ -284,8 +283,8 @@
284283
return str;
285284
}
286285
});
287-
}
288-
286+
}
287+
289288
if (key === "style") {
290289
var str = attr.charAt(0).toUpperCase() + attr.slice(1);
291290
var objName = str.replace(/Options$/,'')+"Style";
@@ -318,8 +317,8 @@
318317
orgAttributes: orgAttributes
319318
}; // return
320319

321-
};
322-
Attr2Options.$inject= ['$parse', '$timeout', 'NavigatorGeolocation', 'GeoCoder'];
320+
};
321+
Attr2Options.$inject= ['$parse', '$timeout', '$log', 'NavigatorGeolocation', 'GeoCoder'];
323322

324323
angular.module('ngMap').service('Attr2Options', Attr2Options);
325324
})();

testapp/marker_with_ng_repeat.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727

2828
<body>
2929
<div ng-controller="MyCtrl">
30+
<input type="checkbox" ng-model="draggable" /> Draggable
3031
<map zoom="11" center="[40.74, -74.18]">
3132
<marker ng-repeat="p in positions" position="{{p}}" title="pos: {{p}}"></marker>
3233
</map>
3334
<map zoom="11" center="[40.74, -74.18]">
34-
<marker ng-repeat="p in positions2" position="{{p.pos}}" title="pos: {{p.pos}}"></marker>
35+
<marker ng-repeat="p in positions2" draggable="{{draggable}}" position="{{p.pos}}" title="pos: {{p.pos}}"></marker>
3536
</map>
37+
draggable: {{draggable}}
3638
</div>
3739
</body>
3840
</html>

0 commit comments

Comments
 (0)