【问题标题】:AngularJs SmartTable: adding Template variablesAngularJs SmartTable:添加模板变量
【发布时间】:2017-08-31 15:00:13
【问题描述】:

我使用 SmartTable ,在那张表中我有分页模板。 在表格的页脚中,我需要显示“X 的第 1 页”,所以我使用了 html 模板:

<tfoot>
    <tr>
        <td colspan="{{ct.headCells.length}}" class="text-center">
            <div st-items-by-page="itemsPerPage" 
                 st-pagination="" 
                 st-template="/templates/pagination.custom.html">
            </div>
        </td>
    </tr>
</tfoot>

在我的pagination.html 模板中我有

<li><page-select>{{currentPage}}</page-select> of {{numPages}}</li>

一切都好,currentPagenumPages 显示得很好。

现在,我需要将单词 of 翻译成法语,所以我添加了一个新变量 $scope.ofText = "de"... 并在 HTML 模板中使用它:

<li><page-select>{{currentPage}}</page-select> {{ofText}} {{numPages}}</li>

不显示任何文字而不是{{ofText}}...

如何在模板中添加自定义变量?

【问题讨论】:

  • 在哪里可以解决您的问题?
  • 我最终得到了st-template="/templates/pagination.{{lang}}.html"&gt;...

标签: angularjs smart-table


【解决方案1】:

@Serge,您可以将其添加到“pageSelect.directive.js”文件中。我已将翻译作为范围变量添加到链接函数内的指令中,并显示出来。请看plunker。

https://plnkr.co/edit/bunKjbMpQm8bevUYacFt?p=preview

angular.module('myApp')
    .directive('pageSelect', function() {
      return {
        restrict: 'E',
        template: '<input type="text" class="select-page" ng-model="inputPage" ng-change="selectPage(inputPage)">',
        link: function(scope, element, attrs) {
          scope.$watch('currentPage', function(c) {
            scope.inputPage = c;
          });
          scope.ofStr="de";
        }
      }
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-29
    • 2013-06-28
    • 1970-01-01
    • 2017-08-29
    • 2019-08-08
    • 2019-04-09
    • 1970-01-01
    相关资源
    最近更新 更多