mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 03:30:02 +08:00
fix bug where $eval on undefined throws error
This commit is contained in:
12
src/Scope.js
12
src/Scope.js
@@ -130,7 +130,8 @@ function createScope(parent, services, existing) {
|
||||
$set: bind(instance, setter, instance),
|
||||
|
||||
$eval: function $eval(exp) {
|
||||
if (exp === undefined) {
|
||||
var type = typeof exp;
|
||||
if (type == 'undefined') {
|
||||
for ( var i = 0, iSize = evalLists.sorted.length; i < iSize; i++) {
|
||||
for ( var queue = evalLists.sorted[i],
|
||||
jSize = queue.length,
|
||||
@@ -138,18 +139,19 @@ function createScope(parent, services, existing) {
|
||||
instance.$tryEval(queue[j].fn, queue[j].handler);
|
||||
}
|
||||
}
|
||||
} else if (typeof exp === 'function'){
|
||||
} else if (type === 'function') {
|
||||
return exp.call(instance);
|
||||
} else {
|
||||
} else if (type === 'string') {
|
||||
return expressionCompile(exp).call(instance);
|
||||
}
|
||||
},
|
||||
|
||||
$tryEval: function (expression, exceptionHandler) {
|
||||
var type = typeof expression;
|
||||
try {
|
||||
if (typeof expression == 'function') {
|
||||
if (type == 'function') {
|
||||
return expression.call(instance);
|
||||
} else {
|
||||
} else if (type == 'string'){
|
||||
return expressionCompile(expression).call(instance);
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user