If you just want a one-time/one-way bind to the length of an Array
, use ng-value
instead of ng-model
:
<input ng-value="tripsheets.length" type="text">
If you have a two-way binding that can be changed from the default:
$scope.tripsheet = {
tripsheet_num: $scope.tripsheets.length
};
<input ng-model="tripsheet.tripsheet_num" type="text">
Example in plunker: http://plnkr.co/edit/UM4lyGZSxB1mEcpy9CqJ?p=preview
Finally, it sounds like you may be doing a remote call to a database, so you could use the following strategy:
$scope.tripsheet = {
$resolved: false,
tripsheet_num: null
};
When the remote call succeeds, set $resolved
to true
and also set the value of tripsheet_num
. In the HTML you could do something like this:
<input ng-disabled="!tripsheet.$resolved" ng-model="tripsheet.tripsheet_num" type="text">
Resolve example on plunker: http://plnkr.co/edit/q2Ua8KGqWr6HDphe92q0?p=preview
4
solved getting default data in ng-model input [closed]