Skip to content

Commit ca71ac3

Browse files
committed
changed attribute injection syntax
1 parent 3c31814 commit ca71ac3

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed

dist/ui-scroll-grid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-ui-scroll
33
* https://github.com/angular-ui/ui-scroll.git
4-
* Version: 1.4.1 -- 2016-05-31T21:50:01.591Z
4+
* Version: 1.4.1 -- 2016-06-02T19:39:46.238Z
55
* License: MIT
66
*/
77

dist/ui-scroll-jqlite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-ui-scroll
33
* https://github.com/angular-ui/ui-scroll.git
4-
* Version: 1.4.1 -- 2016-05-31T21:50:01.591Z
4+
* Version: 1.4.1 -- 2016-06-02T19:39:46.238Z
55
* License: MIT
66
*/
77

dist/ui-scroll.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-ui-scroll
33
* https://github.com/angular-ui/ui-scroll.git
4-
* Version: 1.4.1 -- 2016-05-31T21:50:01.591Z
4+
* Version: 1.4.1 -- 2016-06-02T19:39:46.238Z
55
* License: MIT
66
*/
77

@@ -514,21 +514,42 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
514514

515515
function injectValue(expression, value) {
516516
if (expression) {
517+
var match = expression.match(/^(\S+)(?:\s+on\s+(\w(?:\w|\d)*))?$/);
518+
if (!match) throw new Error('Expected injection expression in form of \'target\' or \'target on controller\' but got \'' + expression + '\'');
519+
var target = match[1];
520+
var controllerName = match[2];
517521
var scope = viewportScope;
518-
var s = viewportScope;
519-
var i = expression.indexOf('.');
520-
if (i > 0) {
521-
var ctrlName = expression.slice(0, i);
522-
while (s !== $rootScope) {
523-
if (s.hasOwnProperty(ctrlName) && angular.isFunction(s[ctrlName])) {
524-
scope = s;
525-
expression = expression.slice(i + 1);
522+
if (controllerName) {
523+
var candidate = viewport;
524+
scope = undefined;
525+
while (candidate.length) {
526+
var controller = candidate.attr('ng-controller');
527+
if (controller === controllerName) {
528+
scope = candidate.scope();
526529
break;
527530
}
528-
s = s.$parent;
531+
candidate = candidate.parent();
529532
}
533+
if (!scope) throw new Error('Failed to locate target controller \'' + controllerName + '\' to inject \'' + target + '\'');
530534
}
531-
$parse(expression).assign(scope, value);
535+
$parse(target).assign(scope, value);
536+
/*
537+
let scope = viewportScope;
538+
let s = viewportScope;
539+
let i = expression.indexOf('.');
540+
if (i>0) {
541+
let ctrlName = expression.slice(0, i);
542+
while (s !== $rootScope) {
543+
if (s.hasOwnProperty(ctrlName) && angular.isFunction(s[ctrlName])) {
544+
scope = s;
545+
expression = expression.slice(i+1);
546+
break;
547+
}
548+
s = s.$parent;
549+
}
550+
}
551+
$parse(expression).assign(scope, value);
552+
*/
532553
}
533554
}
534555

src/ui-scroll.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,28 @@ angular.module('ui.scroll', [])
503503

504504
function injectValue(expression, value) {
505505
if (expression) {
506+
let match = expression.match(/^(\S+)(?:\s+on\s+(\w(?:\w|\d)*))?$/);
507+
if (!match)
508+
throw new Error('Expected injection expression in form of \'target\' or \'target on controller\' but got \'' + expression + '\'');
509+
let target = match[1];
510+
let controllerName = match[2];
511+
let scope = viewportScope;
512+
if (controllerName) {
513+
let candidate = viewport;
514+
scope = undefined;
515+
while (candidate.length) {
516+
let controller = candidate.attr('ng-controller');
517+
if (controller === controllerName) {
518+
scope = candidate.scope();
519+
break;
520+
}
521+
candidate = candidate.parent();
522+
}
523+
if (!scope)
524+
throw new Error('Failed to locate target controller \'' + controllerName + '\' to inject \'' + target + '\'');
525+
}
526+
$parse(target).assign(scope, value);
527+
/*
506528
let scope = viewportScope;
507529
let s = viewportScope;
508530
let i = expression.indexOf('.');
@@ -518,6 +540,7 @@ angular.module('ui.scroll', [])
518540
}
519541
}
520542
$parse(expression).assign(scope, value);
543+
*/
521544
}
522545
}
523546

0 commit comments

Comments
 (0)