angular.module('project', [
'ngRoute',
'toastr',
'satellizer',
'ngAnimate',
'ngStorage',
'truncate',
])
.config(['$routeProvider', '$locationProvider', '$authProvider', function ($routeProvider, $locationProvider, $authProvider) {
'use strict';
$locationProvider.hashPrefix('!').html5Mode(false);
$routeProvider
// Root URL.
.when('/', {
redirectTo: '/login',
title: 'Login'
})
.when('/login', {
templateUrl: 'login.html',
controller: 'login',
title: 'Login'
})
.when('/register', {
templateUrl : 'register.html',
controller : 'register',
title : 'Register'
})
.otherwise('/login');
}])
.run(['$window', '$localStorage', '$http', '$rootScope', '$routeParams', '$location', '$route', '$log', 'APP_VERSION', '$templateCache', '$timeout', function ($window, $localStorage, $http, $rootScope, $routeParams, $location, $route, $log, APP_VERSION, $templateCache, $timeout) {
'use strict';
$log.info('Project Version: ' + APP_VERSION);
$rootScope.$on('$routeChangeStart', function (event, next) {
})
$rootScope.$on('$routeChangeSuccess', function() {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'myEvent',
'myData': {
'url': 'datalayer.com',
'title': 'datalayer instance',
'type': 'stories'
},
CartInfo: {
'ecommerce': "ecommerce"
}
});
});
}])
始终为每个页面创建新实例的时间。如何在不创建额外实例的情况下将数据推送到dataLayer?
请指导谢谢
现在更新代码看看 还请帮助创建新实例的原因以及再次感谢