I'm using this
<textarea class="notes" placeholder="Placeholder Text" style="height: 630px;" ng-model="notes"></textarea>
and from what I can understand ng-model="notes" means that the textarea is assigned whatever $scope.notes is. This works correctly, however whenever I edit the text in the textarea, isn't $scope.notes supposed to change as well?
When I use this button:
<button ng-click="saveNotes(notes)"></button>
The value of "notes" is always the original $scope.notes value and not the updated value.
Can someone tell me why this is?
Thanks
Edited to include html code:
<ion-view ng-controller="LectureCtrl" id="userMessagesView" view-title="{{lecture.title}}">
<ion-content>
<div style="position: absolute; top: 20px; left: 30px; right: 60px;">
<div style="height: 100%;">
<iframe class="video" width="560" height="315" src="{{lecture.youtubeLink}}" frameborder="0" allowfullscreen></iframe>
<textarea class="notes" placeholder="Placeholder Text" style="height: 630px;" ng-model="notes" ng-change="updatedNotes"></textarea>
</div>
</div>
</ion-content>
<button ng-click="saveNotes(notes)">
</button>
<ion/view
Think of ng-model as a way to connect your controller variables to your HTML and vice versa. So if you set $scope.notes in your controller and your then use the curly brackets {{ notes }} in your html the variable content will show up in your html i.e.
Controller =>(bound to)=> your HTML ($scope.notes)
But it works both ways (2-way binding). So if you use ng-model in your HTML it will now take that content from the input field and set it to the variable in your controller. You don’t have to do anything as it is done in the background in Angular i.e. if you type in “Hello world” in your text area it is already updated to the variable in the controller. So you don’t need to pass it back with .
Controller <=(bound up to)<= HTML (ng-model="notes")
2-way binding has 3 parts (very simplified):
SIMPLE EXAMPLE OF 2WAY BINDING
YOUR CODE // No eed to pass notes back it already is there in your ctrl
“Umbrella” $scope problem – $scope is not connected to its controller
Now if this already makes sense to you and you have it all setup and you are still experiencing problems then it is most likely you have a $scope problem i.e. the “pipeline” to your controller is disconnected. I think of this as moving from one area code to another i.e. you dial 555 every day and you fly to another state and then try to use 555 but is doesn’t work as the area code is 777. $scope.555 will only work with a controller that knows about 555. If you are a different state (controller) 555 means nothing and Angular in this case will “discard it”. It doesn’t actually discard it just assumes you are smart and dialing elsewhere that it doesn't currently know about (eg internationally) so it passes it along assuming that somewhere in the system something will know what to do with 555.
EXAMPLE OF SCOPE "DISCONNECT"