nativescript-toasty:预期有1个参数,但得到了3.ts(2554)

时间:2019-07-12 15:23:27

标签: angular nativescript toast

我正在跟踪一个教程,该教程在部分代码中使用了此功能:

addToFavorites() { 
    if (!this.favorite) { 
        console.log('Adding to Favorites', this.dish.id); 
        this.favorite = this.favoriteservice.addFavorite(this.dish.id); 
        const toast = new Toasty("Added Dish "+ this.dish.id, "short", "bottom"); 
        toast.show(); 
    } 
}

但是由于这行代码const toast = new Toasty("Added Dish "+ this.dish.id, "short", "bottom"); ,我收到了此错误消息:

  

预期有1个参数,但得到了3.ts(2554)

似乎Toasty类/接口已更改,但是我不知道如何编辑代码以获得相同的功能?

2 个答案:

答案 0 :(得分:3)

Toasty需要1个参数,如下所示: const toast = new Toasty({text:'Toast message'}) 您需要使用: 位置:ToastPosition 和持续时间:ToastDuration

示例:

const toasty = new Toasty({
  text: 'Somethign something...',
  position: ToastPosition.TOP,
  duration: ToastDuration.SHORT
});

完整说明:

从“ nativescript-toasty”导入{Toasty}; // Toasty接受一个对象以自定义其行为/外观。唯一需要的值为text,这是吐司的消息。

const toast = new Toasty({ text: 'Toast message' });
toast.show();

//您也可以将方法链接在一起,并且无需使用这种方法创建对Toasty实例的引用

new Toasty({ text: 'Some Message' })
  .setToastDuration(ToastDuration.LONG)
  .setToastPosition(ToastPosition.BOTTOM)
  .setTextColor(new Color('white'))
  .setBackgroundColor('#ff9999')
  .show();

//或您可以设置Toasty实例的属性

const toasty = new Toasty({
  text: 'Somethign something...',
  position: ToastPosition.TOP,
  android: { yAxisOffset: 100 },
  ios: {
    anchorView: someButton.ios, // must be the native iOS view instance (button, page, action bar, tabbar, etc.)
    displayShadow: true,
    shadowColor: '#fff000',
    cornerRadius: 24
  }
});

toasty.duration = ToastDuration.SHORT;
toasty.textColor = '#fff';
toasty.backgroundColor = new Color('purple');
toasty.show();

答案 1 :(得分:3)

构造函数于2019年6月18日更改为“ 2.0.0重构”,更改自:

constructor(
    text: string,
    duration?: ToastDuration,
    position?: ToastPosition,
    textColor?: Color | string,
    backgroundColor?: Color | string
  ) 

constructor(opts?: ToastyOptions)

https://www.npmjs.com/package/nativescript-toasty/v/2.0.0