$ window error' $ window not defined'使用Angular app中的Google Analytics代码

时间:2016-03-26 17:16:27

标签: javascript jquery angularjs google-analytics

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

错误:' $窗口未定义'

   .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();  
        });

1 个答案:

答案 0 :(得分:2)

也可以注入$ window。

.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();  
        });