If you are using bootstrap I've found that I need to 
have ng-disabled="!btnStatus" and ng-class="{'disabled'=!btnStatus}" to 
have the button function as expected. 

On Wednesday, April 16, 2014 10:24:29 AM UTC-5, Reynier Pérez wrote:
>
> I need to toggle a button state between enabled/disabled if I change the 
> default value of a select element. Take this HTML as example:
>
>     <select 
>         ng-change="statusBtn(btnUpdFee, updFee)" 
>         ng-options="wt.id as wt.name for wt in wtax" 
>         ng-model="updFee" 
>         class="ng-pristine ng-valid"
>     >
>         <option value="0" selected="selected">cm-534be5d66aea3</option>
>         <option value="1" selected="selected">cm-534be5d681a02</option>
>         <option value="2">cm-534be5d68316e</option>
>     </select>
>
>     <button disabled="" ng-click="showCommentModal('updateFee')" 
> class="btn btn-success" id="btnUpdFee"><i class="icon-ok"></i></button>
>
> And this is the code I wrote but it's not working:
>
>     $scope.statusBtn = function(btnId, curValue) {
>         if (curValue != $scope.updFee) {
>             $("#" + btnId).removeAttr("disabled");
>         } else {
>             $("#" + btnId).attr("disabled");
>         }
>     }
>
> This approach doesn't work
>
> I made some changes and now code look like this:
>
>     <button class="btn btn-success" 
> ng-click="showCommentModal('updateFee')" ng-disabled="!btnStatus"><i 
> class="icon-ok"></i></button>
>
>     $scope.$watch("updFee", function(newValue, oldValue) {
>         if (newValue === oldValue) {
>             $scope.btnStatus = false;
>         } else {
>             $scope.btnStatus = true;
>         }
>
>         console.log($scope.btnStatus, newValue, oldValue);
>     });
>
> And this is the output:
>
>     First Page Load (no changes): false undefined undefined
>     First Page Load (no changes): true 2 undefined
>     Changing SELECT: true 1 2
>     Changing SELECT again: true 3 1
>
> But still not working, what I'm doing wrong?
>

-- 
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