我有一个简单的表格被打开,点击选项卡

<form name="instructions" class="form form-horizontal" ng-controller="InstructionsPage">
    <div class="form-group">
        <label for="instruction">Instructions</label>
        <textarea id="instruction" rows="5" class="form-control" ng-model="instructions">
        </textarea>
    </div>
    <button class="btn btn-primary" data-ng-click="saveInstructions()">Save</button>
</form>


及相关控制器

angular.module('myApp.controllers')
       .controller('InstructionsPage', ['$scope', function ($scope) {
           use strict';
           $scope.saveInstructions = function() {
               var data = $scope.instructions;
               // post request with data from textfield inside
           }
       }]);


如何使用GET请求接收数据以使用默认/先前保存的数据填充文本字段?谢谢!

最佳答案

您可以像这样从控制器更新绑定到$scope.instructions <textarea>ng-model变量:

$http({
  method: 'GET',
  url: '/someUrl'
}).then(function successCallback(response) {
  $scope.instructions = response;
}, function errorCallback(response) {

});

10-06 07:44