From 3ab49538a414a36c97ed3735c2473eefcf7be073 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 13 Oct 2010 10:51:16 -0700 Subject: fixed issue where ng:bind would not reset value if expression returned undefined --- regression/filter_repeater.html | 31 +++++++++++++++++++++++++++++++ src/directives.js | 2 +- test/directivesSpec.js | 15 +++++++++++++-- 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 regression/filter_repeater.html diff --git a/regression/filter_repeater.html b/regression/filter_repeater.html new file mode 100644 index 00000000..202a6311 --- /dev/null +++ b/regression/filter_repeater.html @@ -0,0 +1,31 @@ + + + + + + + +

This is a demo of a potential bug in angular.

+

Try the following:

+
    +
  1. Type "foo" on the filter box. +
  2. Clear the contents of the filter box. +
  3. Type "bar" on the filter box. +
  4. Clear the contents of the filter box. +
+

Why doesn't the data goes back to the original?

+
+ Input: +
+ + + + + + + + + +
FooBar
{{record.foo}}{{record.bar}}
+ + \ No newline at end of file diff --git a/src/directives.js b/src/directives.js index 425685f3..c3d732a2 100644 --- a/src/directives.js +++ b/src/directives.js @@ -50,7 +50,7 @@ angularDirective("ng:bind", function(expression){ element.html(''); element.append(value); } else { - element.text(value); + element.text(value === _undefined ? '' : value); } } }, element); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index d8f04b29..e65973dc 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -38,6 +38,16 @@ describe("directives", function(){ expect(element.text()).toEqual('misko'); }); + it('should set text to blank if undefined', function() { + var scope = compile('
'); + scope.a = 'misko'; + scope.$eval(); + expect(element.text()).toEqual('misko'); + scope.a = undefined; + scope.$eval(); + expect(element.text()).toEqual(''); + }); + it('should set html', function() { var scope = compile('
'); scope.html = '
hello
'; @@ -56,10 +66,11 @@ describe("directives", function(){ it('should have $element set to current bind element', function(){ angularFilter.myFilter = function(){ - this.$element.text('HELLO'); + this.$element.addClass("filter"); + return 'HELLO'; }; var scope = compile('
before
after
'); - expect(scope.$element.text()).toEqual("beforeHELLOafter"); + expect(sortedHtml(scope.$element)).toEqual('
before
HELLO
after
'); }); }); -- cgit v1.2.3