在AngularJS中,Adsense停止显示广告的问题可能是因为Adsense代码未在AngularJS应用程序中正确加载和渲染。要解决此问题,您可以尝试以下解决方法:
在控制器中,您需要将Adsense代码包装在$trustedHtml服务中以确保安全性。
app.controller('AdsenseController', function($scope, $sce) {
$scope.adsenseCode = '';
$scope.trustedAdsenseCode = $sce.trustAsHtml($scope.adsenseCode);
});
app.controller('AdsenseController', function($scope, $timeout) {
$timeout(function() {
// 在这里加载Adsense脚本
}, 0);
});
app.directive('adsense', function() {
return {
restrict: 'E',
replace: true,
template: '',
link: function(scope, element, attrs) {
var adsenseCode = attrs.code;
// 将adsenseCode添加到element中,以加载Adsense脚本
}
};
});
然后,在HTML中使用自定义指令:
这些方法中的任何一种都可以帮助您在AngularJS应用程序中正确加载和显示Adsense广告。请根据您的具体情况选择适合您的解决方案。