mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-20 00:10:26 +00:00
fixed issue where ng:bind would not reset value if expression returned undefined
This commit is contained in:
parent
2cb9497d02
commit
3ab49538a4
3 changed files with 45 additions and 3 deletions
31
regression/filter_repeater.html
Normal file
31
regression/filter_repeater.html
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html xmlns:ng="http://angularjs.org">
|
||||
<head>
|
||||
<script type="text/javascript" src="../src/angular-bootstrap.js" ng:autobind></script>
|
||||
</script>
|
||||
</head>
|
||||
<body ng:init="$window.$root = this; data = [{foo: 'foo'},{bar: 'bar'}]">
|
||||
<p>This is a demo of a potential bug in angular.</p>
|
||||
<p>Try the following:</p>
|
||||
<ol>
|
||||
<li> Type "foo" on the filter box.
|
||||
<li> Clear the contents of the filter box.
|
||||
<li> Type "bar" on the filter box.
|
||||
<li> Clear the contents of the filter box.
|
||||
</ol>
|
||||
<p>Why doesn't the data goes back to the original?</p>
|
||||
<hr>
|
||||
Input: <input type="text" name="filterName" id="filterInputField"/>
|
||||
<br/>
|
||||
<table ng:eval="filtered_data = data.$filter(filterName)" style="border: 1px solid black">
|
||||
<tr>
|
||||
<th>Foo</th>
|
||||
<th>Bar</th>
|
||||
</tr>
|
||||
<tr ng:repeat="record in filtered_data">
|
||||
<td>{{record.foo}}</td>
|
||||
<td>{{record.bar}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -50,7 +50,7 @@ angularDirective("ng:bind", function(expression){
|
|||
element.html('');
|
||||
element.append(value);
|
||||
} else {
|
||||
element.text(value);
|
||||
element.text(value === _undefined ? '' : value);
|
||||
}
|
||||
}
|
||||
}, element);
|
||||
|
|
|
|||
|
|
@ -38,6 +38,16 @@ describe("directives", function(){
|
|||
expect(element.text()).toEqual('misko');
|
||||
});
|
||||
|
||||
it('should set text to blank if undefined', function() {
|
||||
var scope = compile('<div ng:bind="a"></div>');
|
||||
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('<div ng:bind="html|html"></div>');
|
||||
scope.html = '<div>hello</div>';
|
||||
|
|
@ -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('<div>before<div ng:bind="0|myFilter"></div>after</div>');
|
||||
expect(scope.$element.text()).toEqual("beforeHELLOafter");
|
||||
expect(sortedHtml(scope.$element)).toEqual('<div>before<div class="filter" ng:bind="0|myFilter">HELLO</div>after</div>');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue