Use ng-model with a label element.

I read the code and ended up in the part where the label element is used with the data-ng model, maybe?

<label class="btn btn-success" data-ng-model="myController.statusFilter" data-btn-radio="'disabled'" data-ng-click="myController.method()"> Disabled </label> 
+6
source share
4 answers

He will not work. Since ngModel should only be used with inputs , since it is associated with two-way data binding.

The shortcut does not apply to user input, so it does not require ngModel. Therefore, if you want to associate a scope variable with a label, you can use expressions .

how

 <label> {{labelText}} </label> 

Note: you must define labelText in your controller, for example $scope.labelText = "Hello"

+5
source

Try using the ng-bind example in Plunker .

+2
source
 <label class="btn btn-success" data-ng-bind="myController.statusFilter" data-btn-radio="'disabled'" data-ng-click="myController.method()"> Disabled </label> 

in this case ng-bind will work.

+1
source

No, because it will serve no purpose. What will the model affect? How would you influence a model when it was attached to a label?

If you are instead trying to update the text inside the label, you should simply put the variable in your template:

 <label class="btn btn-success" data-btn-radio="'disabled'" data-ng-click="myController.method()"> {{ myController.statusFilter }} </label> 
0
source

All Articles