Angular ng-model filter with a predefined word

366 views Asked by At

From the angular example page I've tried this example and works

 Search: <input ng-model="searchText">
    <table id="searchTextResults">
      <tr><th>Name</th><th>Phone</th></tr>
      <tr ng-repeat="friend in friends | filter:searchText">

But I want with angular define a string within HTML

I need such a construction for my website were products frequely has a price change. These prices I grab from a database. Depend on which webpage I am i want to show a price from the database

something like:

<ng-model="searchText = John">

So without having an input.

1

There are 1 answers

6
Davin Tryon On

To set a value for searchText, just initialize it in your controller:

$scope.searchText = 'John';

Otherwise, you can use ng-init, but this should really be reserved for scenarios that require initialization in the view:

<div ng-init="searchText='John'">{{searchText}}</div>