mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
Scope should retrieve $log and $exceptionHandler via $service
- fix $log and $exceptionHandler retrieval - remove reference to non-existent `error` handler - update tests
This commit is contained in:
parent
a6a4c18ecd
commit
9368ea3814
2 changed files with 16 additions and 12 deletions
10
src/Scope.js
10
src/Scope.js
|
|
@ -243,6 +243,7 @@ function createScope(parent, providers, instanceCache) {
|
|||
parent = Parent.prototype = (parent || {});
|
||||
var instance = new Parent();
|
||||
var evalLists = {sorted:[]};
|
||||
var $log, $exceptionHandler;
|
||||
|
||||
extend(instance, {
|
||||
'this': instance,
|
||||
|
|
@ -425,13 +426,13 @@ function createScope(parent, providers, instanceCache) {
|
|||
return expressionCompile(expression).call(instance);
|
||||
}
|
||||
} catch (e) {
|
||||
(instance.$log || {error:error}).error(e);
|
||||
if ($log) $log.error(e);
|
||||
if (isFunction(exceptionHandler)) {
|
||||
exceptionHandler(e);
|
||||
} else if (exceptionHandler) {
|
||||
errorHandlerFor(exceptionHandler, e);
|
||||
} else if (isFunction(instance.$exceptionHandler)) {
|
||||
instance.$exceptionHandler(e);
|
||||
} else if (isFunction($exceptionHandler)) {
|
||||
$exceptionHandler(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -635,5 +636,8 @@ function createScope(parent, providers, instanceCache) {
|
|||
(instance.$service = createInjector(instance, providers, instanceCache))();
|
||||
}
|
||||
|
||||
$log = instance.$service('$log');
|
||||
$exceptionHandler = instance.$service('$exceptionHandler');
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,13 +163,13 @@ describe('scope/model', function(){
|
|||
});
|
||||
|
||||
it('should report error on $excetionHandler', function(){
|
||||
var element = jqLite('<div></div>');
|
||||
var scope = createScope();
|
||||
scope.$exceptionHandler = function(e){
|
||||
this.error = e;
|
||||
};
|
||||
var errors = [],
|
||||
errorLogs = [],
|
||||
scope = createScope(null, {}, {$exceptionHandler: function(e) {errors.push(e)},
|
||||
$log: {error: function(e) {errorLogs.push(e)}}});
|
||||
scope.$tryEval(function(){throw "myError";});
|
||||
expect(scope.error).toEqual("myError");
|
||||
expect(errors).toEqual(["myError"]);
|
||||
expect(errorLogs).toEqual(["myError"]);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -215,8 +215,8 @@ describe('scope/model', function(){
|
|||
});
|
||||
|
||||
describe('$new', function(){
|
||||
it('should $new should create new child scope and $become controller', function(){
|
||||
var parent = createScope(null, {exampleService: function(){return 'Example Service';}});
|
||||
it('should create new child scope and $become controller', function(){
|
||||
var parent = createScope(null, angularService, {exampleService: 'Example Service'});
|
||||
var child = parent.$new(temp.InjectController, 10);
|
||||
expect(child.localService).toEqual('Example Service');
|
||||
expect(child.extra).toEqual(10);
|
||||
|
|
@ -229,7 +229,7 @@ describe('scope/model', function(){
|
|||
|
||||
describe('$become', function(){
|
||||
it('should inject properties on controller defined in $inject', function(){
|
||||
var parent = createScope(null, {exampleService: function(){return 'Example Service';}});
|
||||
var parent = createScope(null, angularService, {exampleService: 'Example Service'});
|
||||
var child = createScope(parent);
|
||||
child.$become(temp.InjectController, 10);
|
||||
expect(child.localService).toEqual('Example Service');
|
||||
|
|
|
|||
Loading…
Reference in a new issue