2016-05-23 81 views
0

我有简单的表格被打开点击选项卡在页面打开填充文本框

<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请求来用默认的文本字段接收数据/先前保存数据?谢谢!

回答

1

您只需更新$scope.instructions变量,它绑定到<textarea>ng-model从您的控制器是这样的:

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

}); 
+0

谢谢你,我已经赶上一个想法! –

+0

没问题。很高兴知道您可以提前解决您的问题! – thepio