Skip to content

Commit a5ce8ac

Browse files
Merge pull request #50 from angular/master
Update upstream
2 parents fbb95d6 + 01d6a47 commit a5ce8ac

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

src/ng/directive/ngStyle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
</example>
5353
*/
5454
var ngStyleDirective = ngDirective(function(scope, element, attr) {
55-
scope.$watch(attr.ngStyle, function ngStyleWatchAction(newStyles, oldStyles) {
55+
scope.$watchCollection(attr.ngStyle, function ngStyleWatchAction(newStyles, oldStyles) {
5656
if (oldStyles && (newStyles !== oldStyles)) {
5757
forEach(oldStyles, function(val, style) { element.css(style, '');});
5858
}
5959
if (newStyles) element.css(newStyles);
60-
}, true);
60+
});
6161
});

src/ngResource/resource.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,9 @@ angular.module('ngResource', ['ng']).
830830

831831
function cancelRequest(value) {
832832
promise.catch(noop);
833-
timeoutDeferred.resolve(value);
833+
if (timeoutDeferred !== null) {
834+
timeoutDeferred.resolve(value);
835+
}
834836
}
835837
};
836838

test/ng/directive/ngStyleSpec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,33 @@ describe('ngStyle', function() {
2323
}));
2424

2525

26+
it('should not deep watch objects', inject(function($rootScope, $compile) {
27+
element = $compile('<div ng-style="{height: heightObj}"></div>')($rootScope);
28+
$rootScope.$digest();
29+
expect(parseInt(element.css('height') + 0, 10)).toEqual(0); // height could be '' or '0px'
30+
$rootScope.heightObj = {toString: function() { return '40px'; }};
31+
$rootScope.$digest();
32+
expect(element.css('height')).toBe('40px');
33+
34+
element.css('height', '10px');
35+
$rootScope.heightObj.otherProp = 123;
36+
$rootScope.$digest();
37+
expect(element.css('height')).toBe('10px');
38+
}));
39+
40+
41+
it('should support binding for object literals', inject(function($rootScope, $compile) {
42+
element = $compile('<div ng-style="{height: heightStr}"></div>')($rootScope);
43+
$rootScope.$digest();
44+
expect(parseInt(element.css('height') + 0, 10)).toEqual(0); // height could be '' or '0px'
45+
$rootScope.$apply('heightStr = "40px"');
46+
expect(element.css('height')).toBe('40px');
47+
48+
$rootScope.$apply('heightStr = "100px"');
49+
expect(element.css('height')).toBe('100px');
50+
}));
51+
52+
2653
it('should support lazy one-time binding for object literals', inject(function($rootScope, $compile) {
2754
element = $compile('<div ng-style="::{height: heightStr}"></div>')($rootScope);
2855
$rootScope.$digest();

test/ngResource/resourceSpec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,25 @@ describe('cancelling requests', function() {
21022102

21032103
expect(creditCard.$cancelRequest).toBe(noop);
21042104
});
2105+
2106+
it('should not break when calling old `$cancelRequest` after the response arrives', function() {
2107+
$httpBackend.whenGET('/CreditCard').respond({});
2108+
2109+
var CreditCard = $resource('/CreditCard', {}, {
2110+
get: {
2111+
method: 'GET',
2112+
cancellable: true
2113+
}
2114+
});
2115+
2116+
var creditCard = CreditCard.get();
2117+
var cancelRequest = creditCard.$cancelRequest;
2118+
2119+
$httpBackend.flush();
2120+
2121+
expect(cancelRequest).not.toBe(noop);
2122+
expect(cancelRequest).not.toThrow();
2123+
});
21052124
});
21062125

21072126
describe('configuring `cancellable` on the provider', function() {

0 commit comments

Comments
 (0)