gpt4 book ai didi

javascript - $window 错误 '$window not defined' Angular 应用程序中的谷歌分析代码

转载 作者:行者123 更新时间:2023-11-30 16:11:08 24 4
gpt4 key购买 nike

当尝试运行 GA (谷歌分析代码)在我的 Angular 应用中。

错误:$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) $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();
});

关于javascript - $window 错误 '$window not defined' Angular 应用程序中的谷歌分析代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36238336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com