diff --git a/src/ng/parse.js b/src/ng/parse.js index 8b3f145a8211..99f9bc1f02f5 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -620,9 +620,9 @@ Parser.prototype = { var middle; var token; if ((token = this.expect('?'))) { - middle = this.ternary(); + middle = this.assignment(); if ((token = this.expect(':'))) { - return this.ternaryFn(left, middle, this.ternary()); + return this.ternaryFn(left, middle, this.assignment()); } else { this.throwError('expected :', token); } diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js index 2147c4b0b0d1..ede03a373c84 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -398,6 +398,17 @@ describe('parser', function() { expect(scope.b).toEqual(234); }); + it('should evaluate assignments in ternary operator', function() { + scope.$eval('a = 1 ? 2 : 3'); + expect(scope.a).toBe(2); + + scope.$eval('0 ? a = 2 : a = 3'); + expect(scope.a).toBe(3); + + scope.$eval('1 ? a = 2 : a = 3'); + expect(scope.a).toBe(2); + }); + it('should evaluate function call without arguments', function() { scope['const'] = function(a,b){return 123;}; expect(scope.$eval("const()")).toEqual(123);