mTuran
mTuran

Reputation: 1824

Binding value to input in Angular JS

I have input like this

<input type="text" name="widget.title" ng-model="widget.title" value="{{widget.title}}"/>

I want to change input value dynamically so i use that but it doesn't change the value:

$scope.widget.title = 'a';

Upvotes: 40

Views: 171213

Answers (5)

Danny Mora
Danny Mora

Reputation: 21

Some times there are problems with funtion/features that do not interact with the DOM

try to change the value sharply and then assign the $scope

document.getElementById ("textWidget") value = "<NewVal>";
$scope.widget.title = "<NewVal>";

Upvotes: -1

Er. Sushil Singh
Er. Sushil Singh

Reputation: 21

Use ng-value for set value of input box after clicking on a button:

"input type="email"  class="form-control" id="email2" ng-value="myForm.email2" placeholder="Email"

and

Set Value as:

 $scope.myForm.email2 = $scope.names[0].success;

Upvotes: 2

Frank6
Frank6

Reputation: 1203

If you don't wan't to use ng-model there is ng-value you can try.

Here's the fiddle for this: http://jsfiddle.net/Rg9sG/1/

Upvotes: 18

Hablu
Hablu

Reputation: 193

{{widget.title}} Try this it will work

Upvotes: -6

Dan Caragea
Dan Caragea

Reputation: 1794

You don't need to set the value at all. ng-model takes care of it all:

  • set the input value from the model
  • update the model value when you change the input
  • update the input value when you change the model from js

Here's the fiddle for this: http://jsfiddle.net/terebentina/9mFpp/

Upvotes: 69

Related Questions