fix(filter.ngdoc): Check if "input" variable is defined

By default, "greeting" textfield in this example is prepopulated with "hello" text, but it's pretty easy to copy just filter code to use it in your app. If your textfield is empty while app loads, you'll get an error: "Error: [$interpolate:interr] Can't interpolate: Reverse: {{greeting|reverse}} TypeError: Cannot read property 'length' of undefined". To prevent this, we should check "input" variable, and proceed only in case it is defined.

Closes #6819.
This commit is contained in:
Renat Yakubov
2014-03-24 22:44:08 +03:00
committed by Tobias Bosch
parent 17fa2468bc
commit a275d539f9

View File

@@ -103,6 +103,7 @@ text upper-case.
angular.module('MyReverseModule', []).
filter('reverse', function() {
return function(input, uppercase) {
input = input || '';
var out = "";
for (var i = 0; i < input.length; i++) {
out = input.charAt(i) + out;