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

Allow directive's bi-directional isolate scope to do deep equality check #3491

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -942,13 +942,14 @@ function $CompileProvider($provide) {
$element = attrs.$$element;

if (newIsolateScopeDirective) {
var LOCAL_REGEXP = /^\s*([@=&])(\??)\s*(\w*)\s*$/;
var LOCAL_REGEXP = /^\s*([@=&])(\??)(\*?)\s*(\w*)\s*$/;

var parentScope = scope.$parent || scope;

forEach(newIsolateScopeDirective.scope, function(definition, scopeName) {
var match = definition.match(LOCAL_REGEXP) || [],
attrName = match[3] || scopeName,
attrName = match[4] || scopeName,
eq = (match[3] == '*'),
optional = (match[2] == '?'),
mode = match[1], // @, =, or &
lastValue,
Expand Down Expand Up @@ -995,6 +996,11 @@ function $CompileProvider($provide) {
parentSet(parentScope, parentValue = lastValue = scope[scopeName]);
}
}

if (eq) {
this.eq = true;
}

return parentValue;
});
break;
Expand Down
26 changes: 26 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,8 @@ describe('$compile', function() {
optref: '=?',
optrefAlias: '=? optref',
optreference: '=?',
eqref: '=*',
eqrefAlias: '=* eqref',
expr: '&',
exprAlias: '&expr'
},
Expand Down Expand Up @@ -2166,6 +2168,30 @@ describe('$compile', function() {
}));
});

describe('equality object reference', function() {
it('should update local reference to array when origin changes without $digest errors', inject(function() {
$rootScope.list = [{
name: 'Mark',
value: 45
}, {
name: 'Misko',
value: 52
}];
$rootScope.query = "";
$rootScope.$apply();

compile('<div><span my-component eqref="list | filter:query">');

expect(componentScope.eqref).toEqual($rootScope.list);
expect(componentScope.eqrefAlias).toEqual(componentScope.eqref);

$rootScope.query = "Ma";
$rootScope.$apply();

expect(componentScope.eqref).toEqual([$rootScope.list[0]]);
expect(componentScope.eqrefAlias).toEqual([$rootScope.list[0]]);
}));
});

describe('executable expression', function() {
it('should allow expression execution with locals', inject(function() {
Expand Down