Skip to content

bug: beta6 to rc2 - scope problem #3473

Closed

Description

@tigrus

Type: bug

Platform: all

I have code like this:

  <ion-side-menus>
    <ion-side-menu-content>
        <ion-nav-bar class="bar-dark bar-header">
          <ion-nav-buttons side="left">
            <button class="button button-icon button-clear ion-navicon" menu-toggle="left">
            </button>
          </ion-nav-buttons>
          <ion-nav-buttons side="right" class="no-top" ng-if="user">
            <button class="icon-right ion-plus button">
              {{user.balance | currency }} &nbsp;&nbsp;
            </button>
          </ion-nav-buttons>
        </ion-nav-bar>
        <ion-nav-view animation="slide-left-right" name="menu-content"></ion-nav-view>

    </ion-side-menu-content>
    <ion-side-menu side="left">
          <ion-header-bar class="bar-positive" href="#/fantasy/home">
          </ion-header-bar>
          <ion-content class="has-header">
              <ion-list>
                <ion-item nav-clear menu-close href="#/home">
                  Home
                </ion-item>
                <ion-item nav-clear menu-close href="#/login" ng-if="!user">
                  Login
                </ion-item>
                <ion-item nav-clear menu-close href="#/games/all">
                  View All Games
                </ion-item>
                <ion-item nav-clear menu-close href="#/games/my">
                  My Games
                </ion-item>
                <ion-item nav-clear menu-close href="#/logout" ng-if="user">
                  Logout
                </ion-item>
              </ion-list>
            </ion-content>
    </ion-side-menu>
  </ion-side-menus>

Line:
<ion-nav-buttons side="right" class="no-top" ng-if="user">
not works.

Line:
<ion-item nav-clear menu-close href="#/logout" ng-if="user">
works.

In beta6 both line works. In rc2 - first line not working.

{{user.balance}} - works when removing if statement.

Where to dig?

Activity

  1. changed the title [-]beta6 to rc2 - scope problem[/-] [+]bug: beta6 to rc2 - scope problem[/+] on Apr 4, 2015
  2. tigrus commented on Apr 5, 2015

    @tigrus
    Author

    Looks like trouble in rc2 with this line:

    <ion-nav-buttons side="right" class="no-top" ng-if="user">
    

    It's now showing block in both cases - user and !user.

  3. zane-insta commented on Apr 8, 2015

    @zane-insta

    I am having the same problem.

  4. Fayozjon commented on Apr 9, 2015

    @Fayozjon

    I think you have to use ng-if=="user"

  5. piernik commented on Apr 13, 2015

    @piernik

    Me too - looks like ion-nav-buttons copies $scope and not updates it

  6. piernik commented on Apr 13, 2015

    @piernik

    Here is my bug: http://codepen.io/piernik/pen/NPQqgG
    Click Go to list then first - title is default Item. Then click second title changes to Long first title

    There is a bug I think

  7. perrygovier commented on Apr 14, 2015

    @perrygovier
    Collaborator

    Directives copy their parent's scope in the OOP fashion where once they're instantiated they don't automatically update. Does using $parent.user help?

  8. added
    needs: reply
    on Apr 14, 2015
  9. tigrus commented on Apr 14, 2015

    @tigrus
    Author

    @perrygovier no. Only remove of ng-if helps. ng-if="true" also not working.

  10. removed
    needs: reply
    on Apr 14, 2015
  11. piernik commented on Apr 15, 2015

    @piernik

    @perrygovier have You looked at my codepen? There is bug for sure. Looks like navbar is refreshing scope too early - when final scope isn't set yet.
    I think @tigrus has the same problem.

  12. piernik commented on Apr 15, 2015

    @piernik

    @Yuripetusko even in Your codepen it's not working well.
    Click Go to list then first - title is ok
    then second title is ok
    then first again - title is wrong
    navigate a little - title is not always changing as it should

  13. Yuripetusko commented on Apr 15, 2015

    @Yuripetusko

    @piernik Yes you are right! I can see it now. I updated code a little bit so it's cleaner for ionic developers to see the issue. http://codepen.io/Yuripetusko/pen/MYNVxz

    Basically if you go to list, then click first item, then click second item, and then click first one again the title doesn't update even though scope value is definitely updated

  14. adamdbradley commented on Apr 16, 2015

    @adamdbradley
    Contributor
  15. added
    needs: reply
    on Apr 16, 2015
  16. mhartington commented on Apr 16, 2015

    @mhartington
    Contributor

    @piernik looking at your codepen, it should't even work.
    At first glance, there shouldn't be a nested ion-nav-view in list.html. This could be the main cause of confusion with in the apps history logic. There could be a much simpler way of doing what you are trying to do.

  17. piernik commented on Apr 16, 2015

    @piernik

    @mhartington nested view are common thing in ui-router.
    This is only an exmaple to isolate bug.
    In real app I want to use nested view because of different data handling - data which is downloaded by app.item's resolve and then in different views use this data (ex. app.item.details, app.item.gallery, app.item.map). That way I don't have to resolve data for every view - data is simply the same so what for - I also don't have to work on difficult data cache.
    Off course I would be able to do it differently (without nested view) but:

    1. I didn't see in Your docs that I shouldn't use nested view
    2. Only navbar is problem - everything works fine
    3. As I said in ui-router nested view are common thing.

    Please answer my question - should I rewrite my app or can You fix the problem?

    Edit: I can modify parent's navbar in child controller so in nested view I get gid of navbar. Hope it works.

  18. mhartington commented on Apr 16, 2015

    @mhartington
    Contributor

    Right, nesting views is common with ui-router, but for a mobile app paradigm it's not really advised unless you're making an abstract state. ion-nav-view is a container of many views that slide in and out, and take over the entire screen.

    You should probably rewrite the structure and not use a nested ion-nav-view

  19. piernik commented on Apr 17, 2015

    @piernik

    I see that in router I can't use controller with abstract state. why? I thinks it's possible in ui-router
    Here is my code

    .state('app.item', {
        url: "/item/:id",
        abstract: true,
        views: {
            'page@app': {
                controller: "itemCtrl as vm"
            }
        },
        resolve: {
            itemData: ['psDane', '$stateParams', function (psDane, $stateParams) {
                return psDane.pobierzDaneAtrakcji($stateParams);
            }]
        }
    })
    .state('app.item.info', {
        url: "/info",
        views: {
            'page@app': {
                templateUrl: "app/atrakcja/atrakcja-info.html"
            }
        }
    })
    .state('app.item.map', {
        url: "/map",
        views: {
            'page@app': {
                templateUrl: "app/atrakcja/atrakcja-mapa.html",
                controller: "atrakcjaMapaCtrl as vm"
            }
        }
    })
    

    app.item state should be only for common controller for both child states but it is never triggered when going to app.item.info
    Controller without view is not working either:

    .state('app.item', {
        url: "/item/:id",
        abstract: true,
            controller: "itemCtrl as vm",
        resolve: {
            itemData: ['psDane', '$stateParams', function (psDane, $stateParams) {
                return psDane.pobierzDaneAtrakcji($stateParams);
            }]
        }
    })
    
  20. mhartington commented on Apr 17, 2015

    @mhartington
    Contributor

    You can use controllers on abstract states. @piernik please post about this in the forum, it's not really relevant to the issue.

  21. tigrus commented on Apr 24, 2015

    @tigrus
    Author
  22. removed
    needs: reply
    on Apr 24, 2015
  23. locked and limited conversation to collaborators on Sep 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions