当尝试运行 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/