Evaluates the expression in the context of the current scope just like
angular.scope.$eval()
with expression parameter, but also wraps it in a try/catch
block.
If an exception is thrown then exceptionHandler
is used to handle the exception.
var scope = angular.scope(); scope.error = function(){ throw 'myerror'; }; scope.$exceptionHandler = function(e) {this.lastException = e; }; expect(scope.$eval('error()')); expect(scope.lastException).toEqual('myerror'); this.lastException = null; expect(scope.$eval('error()'), function(e) {this.lastException = e; }); expect(scope.lastException).toEqual('myerror'); var body = angular.element(window.document.body); expect(scope.$eval('error()'), body); expect(body.attr('ng-exception')).toEqual('"myerror"'); expect(body.hasClass('ng-exception')).toEqual(true);
angular.scope.$tryEval(expression[, exceptionHandler]);
expression – {string|function()} –
Angular expression to evaluate.
exceptionHandler(optional) – {(function()|DOMElement)} –
Function to be called or DOMElement to be decorated.
{*}
– The result of expression
evaluation.