Leandro Leandro - 2 months ago 43
AngularJS Question

change text when click on md-switch angular-material

i'm using angular-material to build a app, but i have a list component with a text Disabled, it is a option using md-switch, so, i'm trying make this text change to Enabled when i click in that switch

Answer

Try the ng-change documentation: https://docs.angularjs.org/api/ng/directive/ngChange

And as in documentation, in html:

{{text}}

<md-switch aria-label="switch" ng-change="changeText(model)" ng-model="model">
   Switch
</md-switch>

And in the controller:

$scope.changeText = function(model){
    if(model){
       $scope.text = "Enabled";
    }else{
       $scope.text = "Disabled"
    }
}

Hope it helps =)

Comments