0

I have a page with a list of users, I have sort of a weird set up with the user's details being displayed in a sidenav. So the data changes every time the sidenav opens. I can open the sidenav with the data using the list's controller, but really I need to be able to access the user Id from the sidenav's controller. I'm still fairly new to Angular. Here's what I currently have.

<div class="page">
    <div infinite-scroll='vm.getMore()'>
        <table id="userList">
             <tr ng-repeat="user in vm.data" ng-click="vm.openUser(user)"> .... </tr>
        </table>
    </div>
</div>

<md-sidenav class="md-sidenav-right userDetail" md-component-id="right" md-is-locked-open="{{vm2.isEditing}}" ng-class="{{ vm2.currentUser.isActive ? '' : 'disabledUser'}}">
    <div ng-controller="userDetailController as vm2" layout="column" ng-switch on="vm2.isEditing">
        <div ng-switch-default>
             User details...
             <md-button type="submit" ng-click="vm2.editUser()">Edit User</md-button>
        </div>
        <div ng-switch-when="true">
            <input type="text" value="{{vm.currentUser.clientName}}" />
            <md-button ng-click="vm2.saveUser(vm.currentUser)" ***?>Save</md-button>
        </div>
    </div>
</md-sidenav>
  • 1
    The "Angular way" of sharing data between controllers is to write a service that stores the data and inject it into all the controllers that need to access the data. – The Head Rush Jun 24 '16 at 18:10

1 Answers1

0

Please go through on this link.

Passing data between controllers in Angular JS?

I hope this will solve your problem?

Community
  • 1
  • 1
shobhit jain
  • 141
  • 1
  • 9