1

I want to append a signature with date say "Signature 07/08/2015" inside a textarea on a button click. How can I do this is AngularJS way?

Say textarea contains text as "This is a text". After clicking button it should convert to,

This is a text
Signature 07/08/2015

It's pretty easy to do in JavaScript way, but I am entirely beginner with Angular.

Here is what I have tried to get date in app.js,

$scope.getDate = new Date();

I can use this in view as,

<p ng-bind="getDate | date:'MM/dd/yyyy'"></p>

The textarea seems like this,

<textarea type="text" class="form-control" id="description" name="description" ng-model="description"></textarea>

<a href="javascript:" id="add-signature" onclick="addSignature();">add signature</a> // this needs to be modify in angular way.

Simply in short,

  • get textarea value
  • append signature
  • set this new value in textarea

1 Answer 1

1

Try like this

controller

$scope.addSignature=function(){

   $scope.description=$scope.description+ "\nSignature 07/08/2015";
}

View

<a href="javascript:;" id="add-signature" ng-click="addSignature();">add signature</a> 
Sign up to request clarification or add additional context in comments.

2 Comments

I suppose you mean $scope.addSignature instead of $scope.onClick?
@cverb I did the same as you mentioned and this worked. Anik this is amazing and pretty straight forward.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.