Search code examples
angularjsng-bind

angular input ng-bind not working


this is the code:

        <span>{{ vm.GetSalaryItemValue(salaryItem,detail) }}</span>
        <input type="number" class="form-control" data-ng-bind="vm.GetSalaryItemValue(salaryItem,detail)" />
        <textarea  class="form-control" data-ng-bind="vm.GetSalaryItemValue(salaryItem,detail)" rows="1"
                    ng-blur="vm.SalaryItemValueChanged($event,salaryItem,detail)"></textarea>               

span and textarea are working correctly and shows value, but input tag not working and display nothing. (span and textarea are for testing only) (salaryItem,detail are passing correctly), if I change ng-bind to ng-model, value will be displayed but an error will be throw.

any idea?


Solution

  • If you want one way binding to a textbox's value, i.e. from a calculated function, use ng-value. Just be warned that any input placed in there will not be able to be read. This is only really useful for a readonly or disabled textbox where you don't need 2-way binding.