2016-05-23 7 views
0

Ich habe einfaches Formular geöffnet wird auf Registerkarte klickenPopulate Textfeld auf Seite Öffnung

<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> 

und zugehörige Controller

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 
      } 
     }]); 

Wie Daten empfangen mit GET-Anfrage Textfeld mit Standard aufzufüllen vorher/gespeichert Daten? Vielen Dank!

Antwort

1

können Sie aktualisieren Sie einfach Ihre $scope.instructions Variable, die auf den <textarea>ng-model von Ihrem Controller wie folgt gebunden ist:

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

}); 
+0

Danke, habe ich eine Idee fangen! –

+0

Kein Problem. Gut zu wissen, dass Sie mit Ihrem Problem weiterkommen können! – thepio