AngularJS get and set value

AngularJS get and set value

本文关键字:value set and get AngularJS      更新时间:2023-09-26

我想在点击按钮的文本区域内添加签名,注明日期为" signature 07/08/2015"。我怎么能做到这是AngularJS的方式?

假设文本区域包含文本为"This is a text"。点击按钮后,它应该转换为

This is a text
Signature 07/08/2015

用JavaScript的方式很容易做到,但我完全是Angular的初学者。

这是我试图在app.js中获取日期,

$scope.getDate = new Date();

我可以在viewas中使用

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

文本区看起来像这样,

<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.

简单地说,

  • 获取textarea value
  • <
  • 附加签名/gh>
  • 在textarea
  • 中设置这个新值

试一下

控制器

$scope.addSignature=function(){
   $scope.description=$scope.description+ "'nSignature 07/08/2015";
}
<

视图/strong>

<a href="javascript:;" id="add-signature" ng-click="addSignature();">add signature</a>