aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Angular.js7
-rw-r--r--src/Scope.js12
-rw-r--r--src/services.js2
-rw-r--r--test/JsonTest.js4
-rw-r--r--test/ParserTest.js5
-rw-r--r--test/ResourceSpec.js7
-rw-r--r--test/ScopeSpec.js15
7 files changed, 39 insertions, 13 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 42e2ce89..e11a0679 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -338,12 +338,11 @@ function merge(src, dst) {
}
}
-function compile(element, parentScope) {
+function compile(element, existingScope) {
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget),
- $element = jqLite(element),
- parent = extend({}, parentScope);
+ $element = jqLite(element);
parent.$element = $element;
- return compiler.compile($element)($element, parent);
+ return compiler.compile($element)($element, existingScope);
}
/////////////////////////////////////////////////
diff --git a/src/Scope.js b/src/Scope.js
index 4d2aa5c3..86d5bc14 100644
--- a/src/Scope.js
+++ b/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) {
diff --git a/src/services.js b/src/services.js
index 8df23564..fa9cdaa4 100644
--- a/src/services.js
+++ b/src/services.js
@@ -213,7 +213,7 @@ function switchRouteMatcher(on, when, dstName) {
return match ? dst : null;
}
-angularService('$route', function(location, params){
+angularService('$route', function(location){
var routes = {},
onChange = [],
matcher = switchRouteMatcher,
diff --git a/test/JsonTest.js b/test/JsonTest.js
index 1ed56da8..4afb7743 100644
--- a/test/JsonTest.js
+++ b/test/JsonTest.js
@@ -82,3 +82,7 @@ JsonTest.prototype.testItShouldSerializeSameObjectsMultipleTimes = function () {
JsonTest.prototype.testItShouldNotSerializeUndefinedValues = function () {
assertEquals('{}', angular.toJson({A:undefined}));
};
+
+JsonTest.prototype.testItShouldParseFloats = function () {
+ expect(fromJson("{value:2.55, name:'misko'}")).toEqual({value:2.55, name:'misko'});
+};
diff --git a/test/ParserTest.js b/test/ParserTest.js
index 7ba65f18..d7fd2f94 100644
--- a/test/ParserTest.js
+++ b/test/ParserTest.js
@@ -147,6 +147,11 @@ LexerTest.prototype.testStatements = function(){
assertEquals(tokens[3].text, ';');
};
+LexerTest.prototype.testNumber = function(){
+ var tokens = new Lexer("0.5").parse();
+ expect(tokens[0].text).toEqual(0.5);
+};
+
ParserTest = TestCase('ParserTest');
ParserTest.prototype.testExpressions = function(){
diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js
index 6e32ce18..546e9aec 100644
--- a/test/ResourceSpec.js
+++ b/test/ResourceSpec.js
@@ -114,6 +114,13 @@ describe("resource", function() {
CreditCard.charge({id:123, amount:10},{auth:'abc'}, callback);
});
+ it('should post charge verb on instance', function(){
+ xhr.expectPOST('/CreditCard/123!charge?amount=10', {id:{key:123}, name:'misko'}).respond({success:'ok'});
+
+ var card = new CreditCard({id:{key:123}, name:'misko'});
+ card.$charge({amount:10}, callback);
+ });
+
it('should create on save', function(){
xhr.expectPOST('/CreditCard', {name:'misko'}).respond({id:123});
var cc = new CreditCard();
diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js
index 6f5485e7..ea63fea4 100644
--- a/test/ScopeSpec.js
+++ b/test/ScopeSpec.js
@@ -21,8 +21,11 @@ describe('scope/model', function(){
});
describe('$eval', function(){
+ var model;
+
+ beforeEach(function(){model = createScope();});
+
it('should eval function with correct this', function(){
- var model = createScope();
model.$eval(function(){
this.name = 'works';
});
@@ -30,18 +33,24 @@ describe('scope/model', function(){
});
it('should eval expression with correct this', function(){
- var model = createScope();
model.$eval('name="works"');
expect(model.name).toEqual('works');
});
it('should do nothing on empty string and not update view', function(){
- var model = createScope();
var onEval = jasmine.createSpy('onEval');
model.$onEval(onEval);
model.$eval('');
expect(onEval).wasNotCalled();
});
+
+ it('should ignore none string/function', function(){
+ model.$eval(null);
+ model.$eval({});
+ model.$tryEval(null);
+ model.$tryEval({});
+ });
+
});
describe('$watch', function(){