Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 13107a5

Browse files
SomeKittenserwinmombay
authored andcommitted
feat(name scopes): Allow users to name scopes
Check for a __ngHintName property on scope/controllerAs value. If found, name the scope that in the Scopes panel. Fixes #84
1 parent f7ef64b commit 13107a5

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/modules/scopes.js

+27-4
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ var TYPES = [
303303
function scopeDescriptor (elt, scope) {
304304
var val,
305305
theseTypes = [],
306+
noDataDefault = 'scope.$id=' + scope.$id,
306307
type;
307308

308309
if (elt) {
@@ -313,11 +314,33 @@ function scopeDescriptor (elt, scope) {
313314
}
314315
}
315316
}
316-
if (theseTypes.length === 0) {
317-
return 'scope.$id=' + scope.$id;
318-
} else {
319-
return theseTypes.join(' ');
317+
if (theseTypes.length) {
318+
// We have info from the HTML
319+
noDataDefault = theseTypes.join(' ');
320+
321+
if (theseTypes[0].indexOf(' as ') > -1) {
322+
// It's controllerAs
323+
var caPrefix = theseTypes[0].match(/ as ([^"]+)"/);
324+
325+
if (caPrefix && caPrefix[1]) {
326+
// We have enough info to make a decision
327+
return scope[caPrefix[1]].__ngHintName || noDataDefault;
328+
}
329+
}
330+
}
331+
332+
if (scope.__ngHintName) {
333+
// Without controllerAs, we need to check to ensure the name wasn't
334+
// inherited from the parent scope
335+
if (scope.$parent) {
336+
var sameNameAsParent = scope.__ngHintName === scope.$parent.__ngHintName;
337+
}
338+
339+
// If we have a name, use it, otherwise use the next best thing
340+
return sameNameAsParent ?
341+
noDataDefault : scope.__ngHintName;
320342
}
343+
return noDataDefault;
321344
}
322345

323346
function humanReadableWatchExpression (fn) {

0 commit comments

Comments
 (0)