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.
span和textarea正常工作并显示值,但输入标记不起作用并且不显示任何内容。 (span和textarea仅用于测试)(salaryItem,详细信息正确传递),如果我将ng-bind更改为ng-model,将显示值但是将抛出错误。
any idea?
任何想法?
2 个解决方案
#1
3
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.
如果您希望单向绑定到文本框的值,即从计算函数绑定,请使用ng-value。请注意,放在那里的任何输入都将无法读取。这对于不需要双向绑定的只读或禁用文本框非常有用。
#2
3
Change the input code to use ng-model
instead ng-bind
and assign the output of vm.GetSalaryItemValue(salaryItem,detail)
to a scope variable:
更改输入代码以使用ng-model而不是ng-bind,并将vm.GetSalaryItemValue(salaryItem,detail)的输出分配给范围变量:
<div ng-init="inputNumber = vm.GetSalaryItemValue(salaryItem,detail)"></div>
<input type="number" class="form-control" data-ng-model="inputNumber" />
You need to assign the scope variable because ng-model
cannot execute the function.
您需要分配范围变量,因为ng-model无法执行该功能。
#1
3
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.
如果您希望单向绑定到文本框的值,即从计算函数绑定,请使用ng-value。请注意,放在那里的任何输入都将无法读取。这对于不需要双向绑定的只读或禁用文本框非常有用。
#2
3
Change the input code to use ng-model
instead ng-bind
and assign the output of vm.GetSalaryItemValue(salaryItem,detail)
to a scope variable:
更改输入代码以使用ng-model而不是ng-bind,并将vm.GetSalaryItemValue(salaryItem,detail)的输出分配给范围变量:
<div ng-init="inputNumber = vm.GetSalaryItemValue(salaryItem,detail)"></div>
<input type="number" class="form-control" data-ng-model="inputNumber" />
You need to assign the scope variable because ng-model
cannot execute the function.
您需要分配范围变量,因为ng-model无法执行该功能。