0

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.

Richard
  • 9
  • 4

1 Answers1

0

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>
Davin Tryon
  • 66,517
  • 15
  • 143
  • 132
  • that's not what i need. I've multiple webpages which call the same controller (this controller grabs a database). Each webpage should make a different view, with data from this controller. – Richard Dec 19 '13 at 11:00
  • Just define ng-init and ng-model on the same element: `` – Dmitry Evseev Dec 19 '13 at 11:20
  • @DmitryEvseev The OP says, "without having an input". Not sure what this means... :) – Davin Tryon Dec 19 '13 at 11:25
  • @DmitryEvseev Evseev Your solution works! It would be perfect if i could hide the 'input box', but i will figure that out somehow, thank you for your comment – Richard Dec 19 '13 at 12:40
  • @DavinTryon I meant without using the 'input' element. – Richard Dec 19 '13 at 12:41
  • @Richard Yep, missed the input remark. You're not tied to input here. The `ng-init` directive can be used on any element. You could use it on a table even: ``. But think about some good consistent place. If you're bootstrapping controller with `ng-controller` then use `ng-init` also on that element.
    – Dmitry Evseev Dec 19 '13 at 15:22