【问题标题】:append a string to the beginning of ng-model将字符串附加到 ng-model 的开头
【发布时间】:2016-02-16 21:37:41
【问题描述】:

我需要在 ng-model 变量中附加一个字符串。 我正在使用 ng-model 进行过滤。我正在搜索的所有元素都以字符串“模板”开头。 我想将它添加到 ng-model 中,以便不在我的搜索输入中输入“模板”。 我正在使用 ng-model 进行另一个过滤。

这是我的代码:

<label>Search By Station: <input ng-model="searchText.screensId"></label>
<label>Search By Template: <input ng-model="searchText.template"></label>
<div data-ng-repeat="msg in messages | filter:searchText">

我想在 'searchText.template' 值的开头插入字符串“template”。

(像这样:“模板”+searchText.template)

【问题讨论】:

  • 如果你只想要这个进行过滤,为什么不将字符串附加到过滤器中的searchTextmsg in messages | filter:'template' + searchText。不过,我可能会误解您想要实现的目标。
  • @SzabolcsDézsi - 很抱歉没有提供完整的信息。我正在使用过滤器来获取更多过滤器,所以如果我像你说的那样添加它会影响其他搜索
  • @SzabolcsDézsi - 我试过了,但还是不行。
  • 当内置过滤器不够用时,创建自定义过滤器或使用控制器功能并不难

标签: html angularjs angular-ngmodel


【解决方案1】:

您应该能够像这样在过滤器的开头添加“tempate”:

<label>Search By Station: <input ng-model="searchText.screensId"></label>
<label>Search By Template: <input ng-model="searchText.template"></label>
<div data-ng-repeat="msg in messages | filter:('template'+searchText.template)">

【讨论】:

    猜你喜欢
    • 2018-10-30
    • 1970-01-01
    • 1970-01-01
    • 2019-09-19
    • 2013-11-14
    • 1970-01-01
    • 2017-11-09
    • 2011-08-30
    • 1970-01-01
    相关资源
    最近更新 更多