【问题标题】:Styling Pull to Refresh Nativescript Angular样式拉动以刷新 Nativescript Angular
【发布时间】:2019-08-04 16:22:59
【问题描述】:

我正在关注 Nativescript Angular Pull to Refresh Styling 演示 (Found here),但无法让 this.myListViewComponent 成为 undefined,因此这个 sn-p 永远不会被触发:

if (this.myListViewComponent && this.myListViewComponent.listView) {
  let style = new PullToRefreshStyle();
  style.indicatorColor = new Color("red");
  style.indicatorBackgroundColor = new Color("blue");
  this.myListViewComponent.listView.pullToRefreshStyle = style;
}

这里唯一的区别是它是主页的一部分,正在延迟加载(我不确定这是否重要)。

还有其他方式来设置 PullToRefresh 指示器的样式吗?

以下 sn-p 来自 Nativescript Core 文档,因此不适用于 Angular:

<lv:RadListView.pullToRefreshStyle>
    <lv:PullToRefreshStyle
        indicatorColor="white" 
        indicatorBackgroundColor="blue"/>
</lv:RadListView.pullToRefreshStyle>

显然,以下示例不适用于 Angular 代码。还有另一种我想念的方式,就像这个完全假的伪代码:

<RadListView>
    <ng-template>...</ng-template>
    <PullToRefreshStyle
        indicatorColor="white" 
        indicatorBackgroundColor="blue">
    </PullToRefreshStyle>
</RadListView>

我使用的是 Nativescript 6+。

【问题讨论】:

  • 您能否分享一个 Playground 示例,以证明您提到的 undefined 问题。
  • 嗨 Monaj,该链接包含我使用的代码。我完全按原样使用示例。您知道在 HTML 中而不是在 .ts 文件中使用“PullToRefreshStyle”的方法吗?
  • 这与 Angular 8 有关系吗?我确实有一个 *if 条件。 {N} 源代码将代码放在 ngOnInt 中,但 Angular 文档说将其放在 ngAfterViewInit 中。当我这样做时,好吧,似乎什么都没有发生。大声笑
  • 我建议使用loaded 事件立即获得对组件的访问权限,但如果没有 Playground 示例,我不能说太多。
  • 谢谢 Manoj!是否有链接可以看到loaded 事件的示例。

标签: angular nativescript pull-to-refresh


【解决方案1】:

loaded 事件的处理方式与您可能在 Angular 中使用的任何其他事件一样。

HTML

<RadListView class="list-group" pullToRefresh="true" [items]="countries"
    (itemTap)="onItemTap($event)" (loaded)="onLoaded($event)">
    ....
</RadListView>

TS

onLoaded(event: EventData) {
    let style = new PullToRefreshStyle();
    style.indicatorColor = new Color("red");
    style.indicatorBackgroundColor = new Color("blue");
    (<RadListView>event.object).pullToRefreshStyle = style;
}

Playground Sample

【讨论】:

  • 哇!谢谢你,Manoj!
  • 如何通过 pullToRefresh 触发方法?
  • 如果我理解你的问题,你已经有pullToRefreshInitiated事件,你可以分配一个回调。
  • 您好,它的工作,但完成拉动刷新列表后不会回到原来的位置。有一些差距
猜你喜欢
  • 1970-01-01
  • 2016-07-20
  • 2014-04-16
  • 2013-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-07
  • 2017-08-27
相关资源
最近更新 更多