I am reading a code and got into a part where a label element is been used with data-ng-model is that possible ?
<label class="btn btn-success"
data-ng-model="myController.statusFilter"
data-btn-radio="'disabled'"
data-ng-click="myController.method()">
Disabled
</label>
Since ngModel should only be used with the inputs, since it involves two-way data binding. Label does not deal with user input, thus it does not require the ngModel. So if you want to bind a scope variable to the label then you can use expressions.
The ng-model directive binds the value of HTML controls (input, select, text-area) to application data. It is a part of the FormsModule. This directive is used by itself or as part of a larger form. It accepts a domain model as an optional Input.
NgModel expects the bound element to have a value property, which div s don't have. That's why you get the No value accessor error. I don't know if the input event is supported on all browsers for contenteditable . You could always bind to some keyboard event instead.
It wont't work. Since ngModel should only be used with the inputs, since it involves two-way data binding.
Label does not deal with user input, thus it does not require the ngModel. So if you want to bind a scope variable to the label then you can use expressions.
Like
<label> {{labelText}} </label>
Note : you should define labelText in your controller, like $scope.labelText = "Hello"
Try to use ng-bind
example in Plunker.
<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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With