如何在nativescript,angular 2和打字稿中使用admob

如何在nativescript,angular 2和打字稿中使用admob

问题描述:

Hello Guys

我是Nativescript中的新手并尝试使用admob

我使用带有angular2和typescript的nativescript

但没有任何使用admob by angular2和打字稿的例子



这是我的代码





Hello Guys
I'm a new in Nativescript and trying to use admob
I'm using nativescript with angular2 and typescript
but not there any example using admob by angular2 and typescript

this is my code


import { platformNativeScriptDynamic, NativeScriptModule } from "nativescript-angular/platform";
import { NgModule } from "@angular/core";
import { AppComponent } from "./app.component";
import { admobModule } from "nativescript-admob";

@NgModule({
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    imports: [NativeScriptModule],
})
class AppComponentModule {
    function createBanner() {
        admobModule.createBanner({
        testing: true,
        size: admobModule.AD_SIZE.SMART_BANNER,
        androidBannerId: "ca-app-pub-4225186613160852/8357139706",
        margins: {
            bottom: 0
        }
    }).then(function() {
        console.log("admob createBanner done");
    }, function(error) {
        console.log("admob createBanner error: " + error);
    });
    }

    function createInterstitial(){
         admobModule.createInterstitial({
        testing: true,
        androidInterstitialId: "ca-app-pub-4225186613160852/7938337306",
    }).then(function() {
        console.log("admob createInterstitial done");
    }, function(error) {
        console.log("admob createInterstitial error: " + error);
    });
    }

    function hideBanner () {
    admobModule.hideBanner().then(function() {
        console.log("admob hideBanner done");
    }, function(error) {
        console.log("admob hideBanner error: " + error);
    });
}
}

platformNativeScriptDynamic().bootstrapModule(AppComponentModule);





但我有错误无法找到模块nativescript-admob



我尝试过:



我正在尝试解决它,但我没有成功,所以我需要帮助



but i have error Cannot find module nativescript-admob

What I have tried:

i'm trying to fix it but i'm not success so i need help

你使用
$ b安装了插件吗? $ b

Did you install the plugin using

tns plugin add nativescript-admob





如果问题仍然存在也可以尝试将插件类型定义(它们带有插件)添加到references.d.ts





If your problem continues you can also try to add the plugin type definitions(they come with plugin) to references.d.ts

/// <reference path="./node_modules/nativescript-admob/admob.d.ts"></reference>





我希望你的问题解决了



I hope your problem is solved