0

I'm trying to bind an input (one-way), whoever if I change its value its no longer binding properly

    //controller => on row click => change input
    $scope.getNote = function (note)
    {
        $scope.currentNote = note;
    };

   //view
   <input type="text"  value="{{currentNote.Title}}" >

This is the scenario, getNote is being called and the input is being filled properly. However, when I change the value of the input and call getNote again the input doesn't show the new value even tho its value attribute contains the correct value. So somehow its not showing the correct value to the end user.

eg:
1- First Value from GetNote = "Hello World"
2- I change the value of the input to "Foo" as a normal user
3- Call GetNote again and the I get value="Hello World" but on the screen it displays "Foo"


Hack Solution:

//controller object value copy using jquery
$scope.currentNote = jQuery.extend({}, note);

//view
<input type="text"  ng-model="currentNote.Title" >


Am hoping for an Elegant solution

1
  • You need to use <input type="text" ng-model="currentNote.Title" > Commented Sep 1, 2014 at 17:49

2 Answers 2

1

I think you should try with ngValue directive, as sbaaaang said. But without curly braces (documentation here: https://docs.angularjs.org/api/ng/directive/ngValue).

Edit:

And maybe if you just want to use one-way data binding a div will be enough for your purposes, and not an input. Then you can style it as you want.

Sign up to request clarification or add additional context in comments.

Comments

0

use ng-value="" instead of value="" should fix

i would do:

$scope.getNote = function (note)
    {
        $scope.currentNote = note;
    };

   //view
   <input type="text" ng-model="currentNote.Title" ng-value="currentNote.Title" />

If you still getting problems try also:

$scope.getNote = function (note)
        {
            $scope.$on(function () {
             $scope.currentNote = note;
            });
        };

7 Comments

just tried that but now nothing is showing for the end user, even tho i can see the value change inside firebug
so try using ng-model="" usually forms need it ;) @rtp i updated the answer
ng-model is working properly but i want a one-way binding not two way :(
@rtp yeah remove {{ }} from the ng-value="" expression and it will work, updated answer
same problem, after i change the value its not rebinding properly
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.