JoHksi JoHksi - 2 months ago 5x
Javascript Question

Angular $scope variable not updating

In my angular, I define a scope variable

. When the view is loaded, I load string from my database and set it to
. Then, I populate on a texteditor(Froala) i'm using.

Below is the code for the view:

<div ng-if="formData['page_number'] == 1 ">
<textarea id="froala-sample-2" froala="froalaOptions" ng-model="letter_content"></textarea>

So basically I set
as ng-model for the texteditor. So when I make changes on the texteditor, it modifies the value

One thing I found it weird is that when I modify the text in the texteditor, it changes
inside the div. However, it does not update
outside the div.

When I'm done editing the text in my texteditor, I send send a put request to update the value in the database with
. However, it ends up sending
outside the div which ends up not updating the content.

Why is this weird thing happening?


Actually this has been discussed in more links.

Don't use primitive type variable. Instead of that use object in scope.

For example, Don't use like $scope.primitiveVariale instead of this $scope.object={primitiveVariale:null}

So in view use like object.primitiveVariale then this will be reflect in all the view. Please see the following links.