首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AngularJS:如何在指令中使用货币筛选器?

AngularJS:如何在指令中使用货币筛选器?
EN

Stack Overflow用户
提问于 2014-10-31 21:32:11
回答 1查看 805关注 0票数 0

在此柱塞中,我试图将货币筛选器应用于未被编辑的显示。它是一个编辑到位指令,当输入处于活动状态时显示它,但我希望当它不活动时应用过滤器。

剧本:

代码语言:javascript
复制
var app = angular.module('plunker', []);

app.directive('editInPlace', function () {
  return {
      restrict: 'E',
      scope: {
          value: '='
      },
      template: '<span ng-click="edit()" ng-bind="value" ng-show="!editing"></span><input ng-model="value" ng-blur="onBlur()" ng-show="editing"></input>',
      link: function ($scope, element, attrs) {
          var inputElement = element.find('input');

          // reference the input element
          element.addClass('edit-in-place');

          // Initially, we're not editing.
          $scope.editing = false;

          // ng-click handler to activate edit-in-place
          $scope.edit = function () {
              $scope.editing = true;

              // element not visible until digest complete
              // timeout causes this to run after digest
              setTimeout(function() {
                inputElement[0].focus();
              });
          };

          $scope.onBlur = function() {
              $scope.editing = false;
          };
      }
  };
});

app.controller('MainCtrl', function($scope) {
  $scope.contacts = [
    {name: 'Katniss', total: 35645.58}, 
    {name: 'Peeta', total: 25178.21}
  ];


});

意见:

代码语言:javascript
复制
<body ng-controller="MainCtrl">
    <ul style="margin-top:20px;">
      <li ng-repeat="contact in contacts">
        {{contact.name}} -- 
          <edit-in-place value="contact.total"></edit-in-place>
      </li>
  </ul>
  <hr/>
  <pre>{{contacts}}</pre>
  <hr/>
  </body>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-31 21:43:57

您使用过滤器的方式与在任何其他模板中使用它的方式相同:

代码语言:javascript
复制
template: '<span ng-click="edit()" ng-show="!editing">{{ value | currency}}</span><input ng-model="value" ng-blur="onBlur()" ng-show="editing"></input>'

这是你的改性柱塞

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26683702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档