@@ -303,6 +303,7 @@ var TYPES = [
303
303
function scopeDescriptor ( elt , scope ) {
304
304
var val ,
305
305
theseTypes = [ ] ,
306
+ noDataDefault = 'scope.$id=' + scope . $id ,
306
307
type ;
307
308
308
309
if ( elt ) {
@@ -313,11 +314,33 @@ function scopeDescriptor (elt, scope) {
313
314
}
314
315
}
315
316
}
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 ( / a s ( [ ^ " ] + ) " / ) ;
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 ;
320
342
}
343
+ return noDataDefault ;
321
344
}
322
345
323
346
function humanReadableWatchExpression ( fn ) {
0 commit comments