用typescript 封装 hbuilder的plus对像
写 plus.ts 服务
import { Injectable } from '@angular/core'; declare var plus; @Injectable() export class Plus { /** * 消息提醒 * @param msg 消息 */ toast(msg) { plus.nativeUI.toast(msg, { duration: "long" }); } }
在app.module.ts中加入服务
import { Plus } from '../providers/plus';
@NgModule({
declarations: [...
],
imports: [IonicModule.forRoot(ConferenceApp)
],
bootstrap: [IonicApp],
entryComponents: [...
],
providers: [..., Plus]
})
export class AppModule { }在页面里注入服务
import { Plus } from '../../providers/plus';
@Component({
templateUrl: '../..'
})
export class TabsPage {constructor(navParams: NavParams, plus: Plus) {
**plus.toast("aa");**
}
}
评论已关闭