Wednesday, 15 April 2015

javascript - Defining global functions and properties accessible by AngularJS factory and controllers -



javascript - Defining global functions and properties accessible by AngularJS factory and controllers -

i'm working on angularjs app. when error thrown, want custom handling of error. that, i've done following:

var myapp = angular.module('myapp', []); myapp.factory('$exceptionhandler', function($rootscope) { homecoming function(exception, cause) { seek { console.log('unhandled error happening in version ' + $rootscope.app_version); console.log('error happened @ ' + $rootscope.getformatteddatetime()); } grab (uex1) { console.log('unable log unhandled exception.'); } }; }); myapp.run(function ($rootscope) { $rootscope.app_version = '1.0'; $rootscope.getformatteddatetime = function() { homecoming '--'; }; });

when run code, this error. guess can't add together $rootscope mill declarations. if that's case, how define globally accessible functions , variables can access them in controllers factory?

thank much assistance can provide.

you cant inject $routescope mill , , not thought however

the best can define new mill , , define property factoy :

app.factory('getappinfofactory',function(){ return{ getappversion:function(){ homecoming app_version = '1.0'; }, getformatteddatetime : function() { homecoming '--'; } });

and can utilize mill whenever/whereever want , :

myapp.factory('$exceptionhandler', function(getappinfofactory) { homecoming function(exception, cause) { seek { console.log('unhandled error happening in version ' + getappinfofactory.getappversion()); console.log('error happened @ ' + getappinfofactory.getappinfofactory()); } grab (uex1) { console.log('unable log unhandled exception.'); } }; });

javascript angularjs

No comments:

Post a Comment