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

Commit f75bf5e

Browse files
committed
fix(ngBind): use same json conversion as $interpolate
Fixes #11716
1 parent cd3673e commit f75bf5e

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

src/Angular.js

+18
Original file line numberDiff line numberDiff line change
@@ -1929,6 +1929,24 @@ function createMap() {
19291929
return Object.create(null);
19301930
}
19311931

1932+
1933+
function stringify(value) {
1934+
if (value == null) { // null || undefined
1935+
return '';
1936+
}
1937+
switch (typeof value) {
1938+
case 'string':
1939+
break;
1940+
case 'number':
1941+
value = '' + value;
1942+
break;
1943+
default:
1944+
value = toJson(value);
1945+
}
1946+
1947+
return value;
1948+
}
1949+
19321950
var NODE_TYPE_ELEMENT = 1;
19331951
var NODE_TYPE_ATTRIBUTE = 2;
19341952
var NODE_TYPE_TEXT = 3;

src/ng/directive/ngBind.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var ngBindDirective = ['$compile', function($compile) {
6060
$compile.$$addBindingInfo(element, attr.ngBind);
6161
element = element[0];
6262
scope.$watch(attr.ngBind, function ngBindWatchAction(value) {
63-
element.textContent = isUndefined(value) ? '' : value;
63+
element.textContent = isUndefined(value) ? '' : stringify(value);
6464
});
6565
};
6666
}

src/ng/interpolate.js

-17
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,6 @@ function $InterpolateProvider() {
111111
replace(escapedEndRegexp, endSymbol);
112112
}
113113

114-
function stringify(value) {
115-
if (value == null) { // null || undefined
116-
return '';
117-
}
118-
switch (typeof value) {
119-
case 'string':
120-
break;
121-
case 'number':
122-
value = '' + value;
123-
break;
124-
default:
125-
value = toJson(value);
126-
}
127-
128-
return value;
129-
}
130-
131114
//TODO: this is the same as the constantWatchDelegate in parse.js
132115
function constantWatchDelegate(scope, listener, objectEquality, constantInterp) {
133116
var unwatch;

test/ng/directive/ngBindSpec.js

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ describe('ngBind*', function() {
4646
expect(element.text()).toEqual('-0false');
4747
}));
4848

49+
they('should jsonify $prop', [[{}, '{}'], [true, 'true'], [false, 'false']], function(prop) {
50+
inject(function($rootScope, $compile) {
51+
$rootScope.bind = prop[0];
52+
element = $compile('<div ng-bind="bind"></div>')($rootScope);
53+
$rootScope.$digest();
54+
expect(element.text()).toEqual(prop[1]);
55+
});
56+
});
57+
4958
it('should one-time bind if the expression starts with two colons', inject(function($rootScope, $compile) {
5059
element = $compile('<div ng-bind="::a"></div>')($rootScope);
5160
$rootScope.a = 'lucas';

0 commit comments

Comments
 (0)