HTML:
<textarea ng-model="user.ban_reason"></textarea>
Initially the ban reason is empty. However I want to provide a default value. But
<textarea ng-model="user.ban_reason">reason</textarea>
Does not work.
Any ideas how to do that?
Inside your controller you can do as below:
$scope.user = {
ban_reason:"reason"
}
Well if there is a situation you still need it to have default text in the template, then you can use ng-init.
<textarea ng-model="text" ng-init="text = 'Hello, this is my default text.'"></textarea>
Your angular app initializes when the documents DOM is ready - thus, overrides the value with your $scope.user.ban_reason
value.
In your controller, define a default value for the model property:
$scope.user = { ban_reason: 'reason' };
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