Hello Luke, Sander

Thanks for the reply.
I'm not using the $index.

Some simplified code:

I have a table created by ngRepeat:

<table class="table table-striped">
    <thead>
        <th>
            <div class="floating" resource-checkbox-all></div>
        </th>
        <th>Name</th>
        <th>Description</th>
        <th>Date </th>
    </thead>
    <tr ng-repeat="resource in resourceData.data">
        <td style="padding-right: 5px; vertical-align: middle"><div
resource-checkbox="{{resource}}"></div></td>
        <td style="padding-right: 5px">{{resource.fullname}}</td>
        <td style="padding-right: 5px">{{resource.description}}</td>
        <td style="padding-right: 5px">{{resource.dateResource |
javaTimeToGmailStyle }}</td>
    </tr>
</table>

The resource-checkbox code looks like this:

portalModule.directive('resourceCheckbox',  ['$rootScope', function
($rootScope) {
    var ResourceCheckboxController  = function ($scope, ResourceService) {
        $scope.isChecked = false;
        $scope.internalResource;
        $scope.checkResource = function($event){
            $event.stopPropagation();
            $scope.isChecked = !$scope.isChecked;
        }

        var readSelectedItems = $rootScope.$on("readSelectedItems",
function (){
            if($scope.isChecked){
                ResourceService.readResource($scope.internalResource.id);
            }
        });

        var unreadSelectedItems = $rootScope.$on("unreadSelectedItems",
function (){
            if($scope.isChecked){
                ResourceService.unreadResource($scope.internalResource.id);
            }
        });
    }

    return {
        restrict: 'A',
        template: '<input type="checkbox" ng-checked="isChecked"
ng-click="checkResource($event)"></input>',
        controller: ResourceCheckboxController,
        link: function(scope, element, attrs){
            scope.internalResource =  JSON.parse(attrs.resourceCheckbox);
        }
    }
}]);


When I check one of the checkboxes on the first page and then navigate to
page two resourceData.data in the ngRepeat segments update's and draws the
new view.  All the resourceCheckboxes on page one get the destroy event.
But when readSelectedItems is broadcasted the checkbox is selected on page
one still seems to be responding to the broadcast and marks the line i
checked on page one as read.

I'm probably doing overlooking something silly, or maybe i'm not
approaching this the right way. All help is welcome.

Thanks in advance.



On Tue, Mar 18, 2014 at 8:22 AM, Sander Elias <[email protected]> wrote:

> hi Johan,
>
> I suspect you are using $index to fill the checkboxes? Without seeing your
> code, it's hard to give you an answer on this. As Luke already said, it
> probably isn't the directive.
> so Are you using $index? if yes, then there is your problem. If not, build
> a plunk/fiddle to show your problem, and one of us will help you fix it!
>
> Regards
> Sander
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "AngularJS" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/angular/h5aiq09TKSQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to