Skip to content

Commit e141438

Browse files
committed
deep-watch object literals, fix typos
1 parent 35f5b5b commit e141438

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/ng/compile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,13 +3065,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
30653065
destination[scopeName] = parentGet(scope);
30663066

30673067
if (definition.collection) {
3068-
removeWatch = scope.$watchCollection(attrs[attrName], function onParentCollectionValueChange(newParentValue) {
3068+
removeWatch = scope.$watchCollection(parentGet, function parentCollectionValueWatchAction(newParentValue) {
30693069
destination[scopeName] = newParentValue;
30703070
});
30713071
} else {
3072-
removeWatch = scope.$watch(attrs[attrName], function onParentValueChange(newParentValue) {
3072+
removeWatch = scope.$watch(parentGet, function parentValueWatchAction(newParentValue) {
30733073
destination[scopeName] = newParentValue;
3074-
});
3074+
}, parentGet.literal);
30753075
}
30763076
removeWatchCollection.push(removeWatch);
30773077
break;

test/ng/compileSpec.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4384,7 +4384,7 @@ describe('$compile', function() {
43844384
}));
43854385

43864386

4387-
it('should not change the isolate when origin does not change', inject(function() {
4387+
it('should not change the isolated scope when origin does not change', inject(function() {
43884388
compile('<div><span my-component ref="{name: name}">');
43894389

43904390
$rootScope.name = 'a';
@@ -4395,6 +4395,34 @@ describe('$compile', function() {
43954395
}));
43964396

43974397

4398+
it('should deep-watch array literals', inject(function() {
4399+
$rootScope.name = 'georgios';
4400+
$rootScope.obj = {name: 'pete'};
4401+
compile('<div><span my-component ow-ref="[{name: name}, obj]">');
4402+
$rootScope.$apply();
4403+
expect(componentScope.owRef).toEqual([{name: 'georgios'}, {name: 'pete'}]);
4404+
4405+
$rootScope.name = 'lucas';
4406+
$rootScope.obj = {name: 'martin'};
4407+
$rootScope.$apply();
4408+
expect(componentScope.owRef).toEqual([{name: 'lucas'}, {name: 'martin'}]);
4409+
}));
4410+
4411+
4412+
it('should deep-watch object literals', inject(function() {
4413+
$rootScope.name = 'georgios';
4414+
$rootScope.obj = {name: 'pete'};
4415+
compile('<div><span my-component ow-ref="{name: name, item: obj}">');
4416+
$rootScope.$apply();
4417+
expect(componentScope.owRef).toEqual({name: 'georgios', item: {name: 'pete'}});
4418+
4419+
$rootScope.name = 'lucas';
4420+
$rootScope.obj = {name: 'martin'};
4421+
$rootScope.$apply();
4422+
expect(componentScope.owRef).toEqual({name: 'lucas', item: {name: 'martin'}});
4423+
}));
4424+
4425+
43984426
it('should not complain when the isolated scope changes', inject(function() {
43994427
compile('<div><span my-component ow-ref="{name: name}">');
44004428

@@ -4430,8 +4458,8 @@ describe('$compile', function() {
44304458
describe('optional one-way binding', function() {
44314459
it('should update local when origin changes', inject(function() {
44324460
compile('<div><span my-component ow-optref="name">');
4433-
expect(componentScope.owOptRef).toBe(undefined);
4434-
expect(componentScope.owOptRefAlias).toBe(componentScope.owOptRef);
4461+
expect(componentScope.owOptref).toBe(undefined);
4462+
expect(componentScope.owOptrefAlias).toBe(componentScope.owOptref);
44354463

44364464
$rootScope.name = 'misko';
44374465
$rootScope.$apply();

0 commit comments

Comments
 (0)