【问题标题】:how to get tab change event nativescript如何获取选项卡更改事件 nativescript
【发布时间】:2016-10-18 22:44:53
【问题描述】:

有没有办法监听我的应用组件中的选项卡变化?

//app.component.ts

import {Component, ElementRef} from '@angular/core';

    @Component({
        selector: 'app-component',
        templateUrl: 'app.component.html' 
    })
    export class AppComponent {

         //this isn't working
         onSelectedIndexChanged(args) {
           console.log("changing");
       }

    }

【问题讨论】:

    标签: angular nativescript


    【解决方案1】:

    要处理TabView 索引更改,您可以使用selecedIndexChangeEvent。例如:

    app.component.html

    <TabView #tabView (selectedIndexChanged)="tabViewIndexChange( tabView.selectedIndex)" class="example-container">
    <StackLayout *tabItem="{title: 'Profile', iconSource: '~/icon.png'}" >
            <ListView [items]='items'>
                <template let-item='item'>
                    <Label [text]='item.itemDesc' ></Label>
                </template>
            </ListView>
        </StackLayout>
        <StackLayout *tabItem="{title: 'Stats'}">
            <Label text="Second tab item"></Label>
        </StackLayout>
        <StackLayout *tabItem="{title: 'Settings'}">
            <Label text="Third tab item"></Label>
        </StackLayout>
    </TabView>
    

    app.component.ts

    public tabViewIndexChange(result){
           alert("Tab View selected index: "+result);
       }
    

    如需进一步帮助,您可以查看示例应用程序here

    【讨论】:

    • 当我切换标签时,该函数似乎从未被调用过。直接从您提供的样本中复制。不过我使用的是 iOS 10……有什么想法吗?
    • 嗨,贾斯汀,我编辑了示例,事件名称有误。现在一切正常。
    猜你喜欢
    • 2013-07-18
    • 1970-01-01
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    • 2011-01-21
    相关资源
    最近更新 更多