0

I'm using Angular JS to try and update the value of a <textarea> using a $http request after a link is clicked to fetch some content in my controllers.js as shown here:

$scope.setDocument = function(docId) {
  $http.get('docs/' + docId + '.json').success(function(data) {
    $scope.content = data.docData;
    console.log('setting document: ' + data.docData);
  });
}

the log statement shows the right document data, but the result is not rendered in the text area on the browser:

<textarea id="main-writer" ng-model="content" class="row-fluid" autofocus="true" cols="48" rows="24"></textarea>

What am I missing here?

1

1 Answer 1

1

Should be ng-model="content" not "docData"

EDIT: You might want to do $scope.$apply(); after setting the new content. Although I don't think it is necessary but worth a try. There is a nice Chrome extension for inspecting AngularJS scopes and bindings. You might want to use that to see what's going on.

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

2 Comments

Thanks, I'm not sure what's happening, but my setDocument function looks like it isn't being bound to the scope. I'll keep messing with it.
The problem ended up being in the link I clicked to call the function <a href="#" ng-click="setDocument(doc.id)">Open</a> removing the # solved the problem. It says so in the documentation here: docs.angularjs.org/api/ng.directive:a

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.