与angular2一起使用烤面包机 [英] Use toastr with angular2

查看:91
本文介绍了与angular2一起使用烤面包机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此节点程序包链接

按照说明进行操作,使打字稿编译器不为所动. 我认为问题与此处所述相同,但我找不到解决方法./p>

有帮助吗?

非常感谢

解决方案

这意味着您可以直接使用toastr对象,而不必像这样导入它:import * as toastr from '...';.

那是为了避免编译错误,您需要包括相应的类型:

/// <reference path="./toaster.d.ts" />

以下是在组件中使用Toastr的方法:

/// <reference path="./toaster.d.ts" />

import {Component} from 'angular2/core';

@Component({
  selector: 'my-app', 
  template: `
    <div (click)="displayToastr()">Display Toastr</div>
  `
})
export class AppComponent {
  constructor() {
    toastr.options = { positionClass: 'toast-bottom-right' };
  }

  displayToastr() {
    toastr.info('message');
  }
}

以下是相应的插件: https://plnkr.co/edit/wzdoisKBrZYTeSX8r7Nd?p=预览.

I'm using this node package link

Following the instructions the typescript compiler gets out of mind. I think the problem is the same described here but I cant find a workaround.

Any help?

Thanks a lot

解决方案

This means that you can use directly the toastr object directly without having to import it like this: import * as toastr from '...';.

That said to avoid compilation error, you need to include the corresponding typings:

/// <reference path="./toaster.d.ts" />

Here is the way to use Toastr in a component:

/// <reference path="./toaster.d.ts" />

import {Component} from 'angular2/core';

@Component({
  selector: 'my-app', 
  template: `
    <div (click)="displayToastr()">Display Toastr</div>
  `
})
export class AppComponent {
  constructor() {
    toastr.options = { positionClass: 'toast-bottom-right' };
  }

  displayToastr() {
    toastr.info('message');
  }
}

Here is the corresponding plunkr: https://plnkr.co/edit/wzdoisKBrZYTeSX8r7Nd?p=preview.

这篇关于与angular2一起使用烤面包机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆