diff options
| author | Misko Hevery | 2010-08-18 16:04:40 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-08-18 16:04:40 -0700 |
| commit | 1087270c95f6bbafd3715c9a5eecdafac79c9daa (patch) | |
| tree | 7c0f0cfb433f69a11756c0b87c01e6927956394f /src | |
| parent | f09415d0de5d383efc9e2cb35d1323a5aac2371d (diff) | |
| download | angular.js-1087270c95f6bbafd3715c9a5eecdafac79c9daa.tar.bz2 | |
added better handling of ng:format=number
Diffstat (limited to 'src')
| -rw-r--r-- | src/Angular.js | 4 | ||||
| -rw-r--r-- | src/formatters.js | 11 |
2 files changed, 10 insertions, 5 deletions
diff --git a/src/Angular.js b/src/Angular.js index 3970f762..4c2e3716 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -4,6 +4,8 @@ if (typeof document.getAttribute == 'undefined') document.getAttribute = function() {}; var consoleNode, + NULL = null, + UNDEFIEND = undefined, PRIORITY_FIRST = -99999, PRIORITY_WATCH = -1000, PRIORITY_LAST = 99999, @@ -105,7 +107,7 @@ function jqLiteWrap(element) { } function isUndefined(value){ return typeof value == 'undefined'; } function isDefined(value){ return typeof value != 'undefined'; } -function isObject(value){ return typeof value == 'object';} +function isObject(value){ return value!=null && typeof value == 'object';} function isString(value){ return typeof value == 'string';} function isNumber(value){ return typeof value == 'number';} function isArray(value) { return value instanceof Array; } diff --git a/src/formatters.js b/src/formatters.js index 9122489f..5c8764ac 100644 --- a/src/formatters.js +++ b/src/formatters.js @@ -1,5 +1,7 @@ function formatter(format, parse) {return {'format':format, 'parse':parse || format};} -function toString(obj) {return (isDefined(obj) && obj !== null) ? "" + obj : obj;} +function toString(obj) { + return (isDefined(obj) && obj !== null) ? "" + obj : obj; +} var NUMBER = /^\s*[-+]?\d*(\.\d*)?\s*$/; @@ -7,10 +9,11 @@ angularFormatter.noop = formatter(identity, identity); angularFormatter.json = formatter(toJson, fromJson); angularFormatter['boolean'] = formatter(toString, toBoolean); angularFormatter.number = formatter(toString, function(obj){ - if (isString(obj) && NUMBER.exec(obj)) { - return obj ? 1*obj : null; + if (obj == null || NUMBER.exec(obj)) { + return obj===null || obj === '' ? null : 1*obj; + } else { + throw "Not a number"; } - throw "Not a number"; }); angularFormatter.list = formatter( |
