Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3ab4953

Browse files
committedOct 13, 2010
fixed issue where ng:bind would not reset value if expression returned undefined
1 parent 2cb9497 commit 3ab4953

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed
 

‎regression/filter_repeater.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE HTML>
2+
<html xmlns:ng="http://angularjs.org">
3+
<head>
4+
<script type="text/javascript" src="../src/angular-bootstrap.js" ng:autobind></script>
5+
</script>
6+
</head>
7+
<body ng:init="$window.$root = this; data = [{foo: 'foo'},{bar: 'bar'}]">
8+
<p>This is a demo of a potential bug in angular.</p>
9+
<p>Try the following:</p>
10+
<ol>
11+
<li> Type "foo" on the filter box.
12+
<li> Clear the contents of the filter box.
13+
<li> Type "bar" on the filter box.
14+
<li> Clear the contents of the filter box.
15+
</ol>
16+
<p>Why doesn't the data goes back to the original?</p>
17+
<hr>
18+
Input: <input type="text" name="filterName" id="filterInputField"/>
19+
<br/>
20+
<table ng:eval="filtered_data = data.$filter(filterName)" style="border: 1px solid black">
21+
<tr>
22+
<th>Foo</th>
23+
<th>Bar</th>
24+
</tr>
25+
<tr ng:repeat="record in filtered_data">
26+
<td>{{record.foo}}</td>
27+
<td>{{record.bar}}</td>
28+
</tr>
29+
</table>
30+
</body>
31+
</html>

‎src/directives.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ angularDirective("ng:bind", function(expression){
5050
element.html('');
5151
element.append(value);
5252
} else {
53-
element.text(value);
53+
element.text(value === _undefined ? '' : value);
5454
}
5555
}
5656
}, element);

‎test/directivesSpec.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ describe("directives", function(){
3838
expect(element.text()).toEqual('misko');
3939
});
4040

41+
it('should set text to blank if undefined', function() {
42+
var scope = compile('<div ng:bind="a"></div>');
43+
scope.a = 'misko';
44+
scope.$eval();
45+
expect(element.text()).toEqual('misko');
46+
scope.a = undefined;
47+
scope.$eval();
48+
expect(element.text()).toEqual('');
49+
});
50+
4151
it('should set html', function() {
4252
var scope = compile('<div ng:bind="html|html"></div>');
4353
scope.html = '<div>hello</div>';
@@ -56,10 +66,11 @@ describe("directives", function(){
5666

5767
it('should have $element set to current bind element', function(){
5868
angularFilter.myFilter = function(){
59-
this.$element.text('HELLO');
69+
this.$element.addClass("filter");
70+
return 'HELLO';
6071
};
6172
var scope = compile('<div>before<div ng:bind="0|myFilter"></div>after</div>');
62-
expect(scope.$element.text()).toEqual("beforeHELLOafter");
73+
expect(sortedHtml(scope.$element)).toEqual('<div>before<div class="filter" ng:bind="0|myFilter">HELLO</div>after</div>');
6374
});
6475

6576
});

0 commit comments

Comments
 (0)
This repository has been archived.