$window错误'$窗口未定义'Angular应用程序中的谷歌分析代码

$window error '$window not defined' with google analytics code in Angular app

本文关键字:代码 谷歌 错误 window 窗口 未定义 Angular 应用程序      更新时间:2023-09-26

我如何定义/注入以允许使用&在我的Angular应用程序中尝试运行GA(谷歌分析代码)时,清除我的js/app.js文件中未定义的$window错误。

错误:"未定义$window"

   .run(function($rootScope, APIServer, social, $location, music, $anchorScroll, $routeParams) {
        // $window.ga('create', 'UA-55555555-5', 'auto'); <-- here
        /*
         * Scroll down to comments if available
         */
        $anchorScroll.yOffset = 70;
        //when the route is changed scroll to the proper element.
        $rootScope.$on('$routeChangeSuccess', function(newRoute, oldRoute) {
            // $window.ga('send', 'pageview', $location.path()); <-- here
            $location.hash($routeParams.scrollTo);
            $anchorScroll();  
        });

Inject$窗口。

.run(function($rootScope, APIServer, social, $location, music, $anchorScroll, $routeParams, $window) {
        // $window.ga('create', 'UA-55555555-5', 'auto'); <-- here
        /*
         * Scroll down to comments if available
         */
        $anchorScroll.yOffset = 70;
        //when the route is changed scroll to the proper element.
        $rootScope.$on('$routeChangeSuccess', function(newRoute, oldRoute) {
            // $window.ga('send', 'pageview', $location.path()); <-- here
            $location.hash($routeParams.scrollTo);
            $anchorScroll();  
        });