Search code examples
htmlangularjsangular-ngmodel

append a string to the beginning of ng-model


I need to append a string to the ng-model variable. I'm using the ng-model for filtering. All my elements that i'm searching are starting with the string "template". I want to add it to the ng-model for not entering "template" in my search input. I'm using the ng-model for another filtering.

Here is my code:

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

I want to insert the string "template" at the beginning of the 'searchText.template' value.

(like this: "template"+searchText.template)


Solution

  • You should be able to add 'tempate' to the beginning of your filter like this:

    <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)">