如何在角度工厂内访问ui-router $ state.go?

时间:2014-05-05 08:59:42

标签: angularjs angular-ui-router

我想在像这样的工厂里使用$state.go

App.factory('$exceptionHandler', ['$log', '$window', '$state', 'stacktraceService', function ($log, $window, $state, stacktraceService) {

    // log the given error to the remote server.
    return function (exception, cause) {

        $log.error.apply($log, arguments);

        try {

            var errorMessage = exception.toString();
            var stackTrace = stacktraceService.print({ e: exception });

            // Log the JavaScript error to the server.
            $.ajax({
                type: "POST",
                url: "./api/systemMessage",
                contentType: "application/json",
                data: angular.toJson({
                    errorUrl: $window.location.href,
                    errorMessage: errorMessage,
                    stackTrace: stackTrace,
                    cause: (cause || "")
                })
            });

            $state.go('error');
        } catch (loggingError) {
            // For Developers - log the log-failure.
            $log.warn("Error logging failed");
            $log.log(loggingError);
         $state.go('error');
        }
    };

    // Return the logging function.
    //return (log);
}]);

我收到此错误

  

未捕获错误:[$ injector:unpr]   http://errors.angularjs.org/1.2.15/ $注射器/ unpr?P0 =%20%24stateProvider%20%3 C-%20%20%24state%20%3 C-%20%24exceptionHandler%20%3 C-%20%24rootScope

请帮助找到解决方案。

0 个答案:

没有答案