Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I have a large Angular page with 100+ rows of data, each with a button in the final column which sets a Bootstrap radiomodel based on which button you click.

//....
<tr>
<td>
data1
</td>
<td>
data2
</td>
<td>    
<div ng-controller="pickSource" class="btn-group " role="group" aria-label="...">
        <label class="btn btn-info btn-xs pickSourceButton takeXxxBtn"    
               ng-model="radioModel" 
               btn-radio="'yyy'" >
            Approve
        </label>
        <label class="btn btn-warning btn-xs pickSourceButton takeYyyBtn"                        
            ng-model="radioModel" 
            btn-radio="'yyy'" >
            Reject
        </label>
        <label class="btn btn-danger btn-xs  pickSourceButton noActionBtn"  
               ng-model="radioModel" 
               btn-radio="'noAction'" >
            Hold
        </label>
    </div>
</td>
</tr>
//... many of these, the picksource block is actually a directive but i simpified here

Button is like this: (approve|reject|hold)

Controller for this button is like this:

controller('pickSource', function ($scope, $log) {
    $scope.radioModel = "noAction";
    $scope.$watch('radioModel', function(newValue, oldValue) {
        if (newValue !== oldValue) {
            $log.log('emitting event');
            //even if i remove this below it is slow
            $scope.$emit('pickSourceButtonDidChange',someDATA);
        }
    });
});

I have a batch operation button which will select the same value (i.e. select source for all the rows) for every row.

Currently I am triggering the events like so:

//inside bootstrap dropdown
if(source == "xxx"){
    el = document.getElementsByClassName('takexxxBtn');
}
else if (source == "yyy"){
    el = document.getElementsByClassName('takeyyyBtn');
}
else{
    el = document.getElementsByClassName('noActionBtn');
}
$timeout(function() {
    angular.element(el).triggerHandler('click');
}, 0);

However, I am getting really poor performance from this. I imagine this is because the click events each have quite a expensive series of actions (I even took out all the code that is triggered when the button is clicked and still got the same performance hit), but I am wondering if there is any alternative. I cannot simply change the underlying data that the trigger executes because I need the UI to update as well (I need button to look like it's clicked, etc.)

Is there any way to do this?

share|improve this question
1  
Could you just call the function that the click event was wired up to in angular over and over again? Paste mode of your dom code. – Mathew Berg May 7 '15 at 15:55
    
Edited to add more context to the question. Also, what you mentioned is exactly what I'm doing...but it's extremely slow – maschwenk May 7 '15 at 16:11
2  
No you're not doing what I'm describing, you're actually running a bunch of click events. What you should be doing is updating all the models instead. – Mathew Berg May 7 '15 at 16:13
    
Ahh, ok misunderstood you. So I guess I need to emit an event to the boostrap buttoncontroller that prompts the model to change. I'll see how that works, seems cleaner. Thanks :) – maschwenk May 7 '15 at 16:17
    
Correct, that's a much cleaner solution + absolutely no dom interaction! :) – Mathew Berg May 7 '15 at 16:20
up vote 1 down vote accepted

Using Matthew Berg's (idk how to link to your profile :S ) solution, I emitted an event from the batch action button controller to the parent controller, caught the event in the parent controller and then broadcast the model changes down to all the bootstrap button controllers. This worked excellently.

Thanks Matt

share|improve this answer
1  
Looks good, glad to help. – Mathew Berg May 7 '15 at 19:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.