Skip to content

ionic2: ion-tabs tabs.getSelected().index got a Error: Cannot read property 'index' of null #10538

@jeneser

Description

@jeneser

Ionic version: (check one with "x")
[ ] 1.x
[ x ] 2.x

I'm submitting a ... (check one with "x")
[ x ] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:

Runtime Error
Error in ./HomePage class HomePage - caused by: Cannot read property 'index' of null

Stack
TypeError: Cannot read property 'index' of null
    at HomePage.onTabsChange (http://localhost:8100/build/main.js:56074:44)
    at CompiledTemplate.proxyViewClass.View_HomePage0.handleEvent_27 (/AppModule/HomePage/component.ngfactory.js:599:34)
    at CompiledTemplate.proxyViewClass.<anonymous> (http://localhost:8100/build/main.js:96697:37)
    at SafeSubscriber.schedulerFn [as _next] (http://localhost:8100/build/main.js:35084:36)
    at SafeSubscriber.__tryOrUnsub (http://localhost:8100/build/main.js:87920:16)
    at SafeSubscriber.next (http://localhost:8100/build/main.js:87869:22)
    at Subscriber._next (http://localhost:8100/build/main.js:87822:26)
    at Subscriber.next (http://localhost:8100/build/main.js:87786:18)
    at EventEmitter.Subject.next (http://localhost:8100/build/main.js:19527:25)
    at EventEmitter.emit (http://localhost:8100/build/main.js:35064:76)

Expected behavior:

When i used var tab_index = this.tabs.getSelected().index; in ionViewDidEnter() and onSlideDidChange(), all going well.I can get index.

But , i write var tab_index = this.tabs.getSelected().index; into onTabsChange(){}.I got the Runtime Error Cannot read property 'index' of null

Steps to reproduce:

reproduce:
http://plnkr.co/edit/BAy0Z7?p=preview

Related code:
Other information:

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

Ionic Framework: 2.0.1
Ionic Native: 2.4.1
Ionic App Scripts: 1.1.0
Angular Core: 2.2.1
Angular Compiler CLI: 2.2.1
Node: 6.9.2
OS Platform: Linux 4.4
Navigator Platform: Linux x86_64
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/55.0.2883.87 Chrome/55.0.2883.87 Safari/537.36

Similar:
#10523

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions