. , " " adsense, , , :
import { Component, AfterViewInit } from '@angular/core';
import { FORM_DIRECTIVES, CORE_DIRECTIVES } from '@angular/common';
@Component({
selector: 'ad',
templateUrl: 'app/views/ad.html',
directives: [ FORM_DIRECTIVES, CORE_DIRECTIVES ]
})
export class AdComponent implements AfterViewInit {
ngAfterViewInit() {
try {
(adsbygoogle = window.adsbygoogle || []).push({});
} catch (e) {}
}
}
<div class="demo-card-wide mdl-card mdl-shadow--2dp ad-card">
<div class="mdl-card__supporting-text">
<ins class="adsbygoogle" style="display:inline-block;width:330px;height:120px" data-ad-client="my_client_number" data-ad-slot="my_ad_slot_number"></ins>
</div>
</div>
Material Design Lite, 2 divs . <ins> , adsense.
AfterViewInit, , adsense adsbygoogle, , DOM. , DOM <ins>.
try/catch, , . . Angular 2 .
, , AdSense, . - Angular 2. Angular 2 RC4 .
, , , TOS ...
Typescript, , .d.ts:
declare interface Window {
adsbygoogle: any[];
}
declare var adsbygoogle: any[];
, Typescript (adsbygoogle = window.adsbygoogle || []).push({}); .