aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Angular.js2
-rw-r--r--src/Formatters.js2
-rw-r--r--src/JSON.js1
-rw-r--r--src/Scope.js2
-rw-r--r--src/Widgets.js3
-rw-r--r--src/directives.js29
-rw-r--r--src/jqLite.js2
7 files changed, 25 insertions, 16 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 27f463ac..db177082 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -6,9 +6,11 @@ if (!window['console']) window['console']={'log':noop, 'error':noop};
var consoleNode,
NOOP = 'noop',
NG_ERROR = 'ng-error',
+ NG_EXCEPTION = 'ng-exception',
NG_VALIDATION_ERROR = 'ng-validation-error',
jQuery = window['jQuery'] || window['$'], // weirdness to make IE happy
_ = window['_'],
+ msie = !!/(msie) ([\w.]+)/.exec(lowercase(navigator.userAgent)),
jqLite = jQuery || jqLiteWrap,
slice = Array.prototype.slice,
angular = window['angular'] || (window['angular'] = {}),
diff --git a/src/Formatters.js b/src/Formatters.js
index 402e8a2b..c1ff82c6 100644
--- a/src/Formatters.js
+++ b/src/Formatters.js
@@ -1,5 +1,5 @@
function formater(format, parse) {return {'format':format, 'parse':parse || format};}
-function toString(obj) {return ""+obj;};
+function toString(obj) {return isDefined(obj) ? "" + obj : obj;};
extend(angularFormatter, {
'noop':formater(identity, identity),
'boolean':formater(toString, toBoolean),
diff --git a/src/JSON.js b/src/JSON.js
index baf3a2fa..69e1b4c0 100644
--- a/src/JSON.js
+++ b/src/JSON.js
@@ -11,6 +11,7 @@ function toPrettyJson(obj) {
};
function fromJson(json) {
+ if (!json) return json;
try {
var parser = new Parser(json, true);
var expression = parser.primary();
diff --git a/src/Scope.js b/src/Scope.js
index 42e7d5e5..4144d456 100644
--- a/src/Scope.js
+++ b/src/Scope.js
@@ -81,7 +81,7 @@ function errorHandlerFor(element, error) {
while (!isRenderableElement(element)) {
element = element.parent() || jqLite(document.body);
}
- elementError(element, 'ng-exception', isDefined(error) ? toJson(error) : error);
+ elementError(element, NG_EXCEPTION, isDefined(error) ? toJson(error) : error);
}
function createScope(parent, Class) {
diff --git a/src/Widgets.js b/src/Widgets.js
index bc61f570..f172eae2 100644
--- a/src/Widgets.js
+++ b/src/Widgets.js
@@ -108,7 +108,7 @@ function inputWidget(events, modelAccessor, viewAccessor, initValue) {
var scope = this,
model = modelAccessor(scope, element),
view = viewAccessor(scope, element),
- action = element.attr('ng-action') || '',
+ action = element.attr('ng-change') || '',
value = view.get() || copy(initValue);
if (isUndefined(model.get()) && isDefined(value)) model.set(value);
this.$eval(element.attr('ng-init')||'');
@@ -120,6 +120,7 @@ function inputWidget(events, modelAccessor, viewAccessor, initValue) {
// therefore we want to prevent default action
return isDefined(initValue);
});
+ view.set(model.get());
scope.$watch(model.get, view.set);
};
}
diff --git a/src/directives.js b/src/directives.js
index 291bea11..de68360e 100644
--- a/src/directives.js
+++ b/src/directives.js
@@ -15,7 +15,7 @@ angularDirective("ng-bind", function(expression){
return function(element) {
var lastValue;
this.$onEval(function() {
- var value = templateFn.call(this);
+ var value = templateFn.call(this, element);
if (value != lastValue) {
element.text(value);
lastValue = value;
@@ -31,16 +31,20 @@ function compileBindTemplate(template){
var bindings = [];
foreach(parseBindings(template), function(text){
var exp = binding(text);
- bindings.push(exp ? function(){
- return this.$eval(exp);
- } : function(){
+ bindings.push(exp ? function(element){
+ var error, value = this.$tryEval(exp, function(e){
+ error = toJson(e);
+ });
+ elementError(element, NG_EXCEPTION, error);
+ return error ? error : value;
+ } : function() {
return text;
});
});
- bindTemplateCache[template] = fn = function(){
+ bindTemplateCache[template] = fn = function(element){
var parts = [], self = this;
foreach(bindings, function(fn){
- var value = fn.call(self);
+ var value = fn.call(self, element);
if (isObject(value)) value = toJson(value, true);
parts.push(value);
});
@@ -54,7 +58,7 @@ angularDirective("ng-bind-template", function(expression){
return function(element) {
var lastValue;
this.$onEval(function() {
- var value = templateFn.call(this);
+ var value = templateFn.call(this, element);
if (value != lastValue) {
element.text(value);
lastValue = value;
@@ -67,7 +71,7 @@ angularDirective("ng-bind-attr", function(expression){
return function(element){
this.$onEval(function(){
foreach(this.$eval(expression), function(bindExp, key) {
- var value = compileBindTemplate(bindExp).call(this);
+ var value = compileBindTemplate(bindExp).call(this, element);
if (key == 'disabled' && !toBoolean(value)) {
element.removeAttr('disabled');
} else {
@@ -135,12 +139,13 @@ angularWidget("@ng-repeat", function(expression, element){
};
});
-angularDirective("ng-action", function(expression, element){
+angularDirective("ng-click", function(expression, element){
return function(element){
var self = this;
element.click(function(){
self.$tryEval(expression, element);
self.$eval();
+ return false;
});
};
});
@@ -167,7 +172,7 @@ function ngClass(selector) {
var value = this.$eval(expression);
if (selector(this.$index)) {
if (isArray(value)) value = value.join(' ');
- element[0].className = (existing + value).replace(/\s\s+/g, ' ');
+ element[0].className = trim(existing + value);
}
}, element);
};
@@ -175,8 +180,8 @@ function ngClass(selector) {
}
angularDirective("ng-class", ngClass(function(){return true;}));
-angularDirective("ng-class-odd", ngClass(function(i){return i % 2 == 1;}));
-angularDirective("ng-class-even", ngClass(function(i){return i % 2 == 0;}));
+angularDirective("ng-class-odd", ngClass(function(i){return i % 2 == 0;}));
+angularDirective("ng-class-even", ngClass(function(i){return i % 2 == 1;}));
angularDirective("ng-show", function(expression, element){
return function(element){
diff --git a/src/jqLite.js b/src/jqLite.js
index 449854d5..3baafd51 100644
--- a/src/jqLite.js
+++ b/src/jqLite.js
@@ -136,7 +136,7 @@ JQLite.prototype = {
addClass: function( selector ) {
if (!this.hasClass(selector)) {
- this[0].className += ' ' + selector;
+ this[0].className = trim(this[0].className + ' ' + selector);
}
},