使用angular将数据绑定值作为默认的固定消息插入textarea中 [英] Insert data-bind values inside textarea as a default canned message using angular

查看:33
本文介绍了使用angular将数据绑定值作为默认的固定消息插入textarea中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何将文本绑定值作为固定消息插入文本区域内.这是一个例子

I'm trying to figure out how I can insert data-bind values inside a textarea as a canned message. Here is an example

<textarea ng-init='message="Buy {{ get_value }} and get {{ free_value }} free for every purchase"' class="text-input referral-message" ng-model="message" rows="5">
</textarea>

我尝试了这种解决方案,但是输出显示的是数据绑定,而不是值本身

I tried this kind of solution, but the output shows the data-bind and not the value itself

$timeout(function() {

    ReferralService.settings().$promise.then(function(settings) {
        $scope.purchase_count = settings.credits;
    });

    $scope.buildMessage = function(val){
      return "Buy " + val + " and get 1 free for every purchase"
    }
}, 1);

推荐答案

我会尽量避免使用 ng-init

如果您想使用 ng-init ,我会尝试以下方法:

If you want to use ng-init, I would try something like:

<textarea ng-init="message=buildMessage(get_value,free_value)" 
          ng-model="message" rows="5">
</textarea>

其中 buildMessage 是:

$scope.buildMessage = function(val,free){
  return "Buy " + val + " and get " + free + " free for every purchase"
}

我认为这是一种干净的方法,不会对HTML产生干扰.

I think this is a clean way and doesn't enter noise to your HTML.

尝试尽可能保留简单的HTML.

Try to stay with simple HTML as possible.

$timeout(function() {

  ReferralService.settings().$promise.then(function(settings) {
    $scope.purchase_count = settings.credits;
  });
});

$scope.buildMessage = function(val){
  return "Buy " + val + " and get 1 free for every purchase"
}

这篇关于使用angular将数据绑定值作为默认的固定消息插入textarea中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆