Mocktheduck Mocktheduck - 2 months ago 16
AngularJS Question

Angular textarea can't be filled with default value

I'm trying to put a default value to my Angular textarea. I think I tried everything possible. Nothing worked. I have a html template

<textarea ng-model="title" required class="textbox" id="feedbackInput" ng-init="title= initvalue"></textarea>


which is connected to the component\controller:

angular
.module('feedbackForm')
.component('feedbackForm', {
templateUrl: 'feedback-form/feedback-form.template.html',
controller: ['$scope', '$routeParams', 'Feedback', '$localStorage',
function FeedbackFormController($scope, $routeParams, Feedback, $localStorage) {
console.log('FeedbackForm Controller');
var self = this;
var feedback = "";
$scope.initvalue = "hhhhhh";
}
]
});


It doesn't work. It doesn't fill my textarea. I tried using this, self, $ctrl... any ideas how to set a default value in my textarea without changing the controller too much.

Answer

Try Like This

<textarea ng-model="title" required class="textbox" id="feedbackInput" ng-init="title= 'initvalue'"></textarea>

or Try Like This in Controller

$scope.title='Default value'

Hope this will help you