2013-10-11 8 views
29

私はAngularJSを初めて使っていますが、私は問題を解決できませんでした。私は基本的にng-clickによって更新されたフォームを持っていますが、いったんテキストボックスにテキストを入力すると、それらのテキストボックスは更新されなくなります。 テキスト入力後にng-modelが更新されなくなった

この

は私のHTML

Edit Course: 
<li ng-repeat="course in courses"> 
    <p> 
    <a ng-click="Edit_Course(course.id)">{{course.course_name}}</a> 
    </p> 
</li> 
<div ng-show="showedit == 1"> 
    <form novalidate ng-submit="edit_course()" class="simple-form"> 
    <label for="form_course_name">Course</label> 
     <input type="text" id="form_course_name" ng-model="edit_course_name"> 
    <label for="form_par">Par</label> 
     <input type="text" id="form_par" ng-model="edit_course_par"> 
    <label for="form_course_location">Course Location</label> 
     <input type="text" id="form_course_location" ng-model="edit_course_location"> 
    <input type="submit" id="submit" value="Edit Course" /> 
    </form> 
</div> 



誰かがあなたのリンクはログインが必要です

$scope.Edit_Course = function (id) { 
    var course = { 
     'course_id' : id 
    }; 

    $http({method: "POST", url: "http://www.dgcharts.com/editcourse", data: course}) 
    .success(function(data, status, headers, config){ 

     thecourse = data["course"]; 
     $scope.edit_course_name = thecourse.course_name; 
     $scope.edit_course_par = thecourse.par; 
     $scope.edit_course_location = thecourse.course_location; 
     $scope.edit_course_id = thecourse.id; 
     $scope.showedit = 1; 
    }) 
} 

答えて

115

リンクをクリックしたときにこれが呼ばれる私の機能です。

私はあなたの問題について推測しなければならない場合、それは角度範囲の問題に関連している可能性があります。代わりにオブジェクトプロパティへのng-modelバインディングを変更してみてください。ので、あなたのhtmlで、代わりのこの詳細は

$scope.course = {}; //only do this if $scope.course has not already been declared 
$scope.course.edit_course_name = thecourse.course_name; 

<input type="text" id="form_course_name" ng-model="edit_course_name"> 

すると、この

<input type="text" id="form_course_name" ng-model="course.edit_course_name"> 

とあなたのJavaScriptでは、AJAXコールバックの上にそれを変更を行いますhttps://github.com/angular/angular.js/wiki/Understanding-Scopes

+5

ありがとうございます。約60秒で修正しました。私は完全に理解していないので、私はこのプロジェクトを続ける前にスコープで必ず読んでいきます。 – EvWill

+3

@Evここでプリミティブではうまくいかない理由を説明します。https://github.com/angular/angular.js/wiki/Understanding-Scopes – Mirko

+3

私はそれを1ヶ月以上間違った方法で使用していました。ありがとうございました。これが正しい方法でない場合、Angularは開発者がそのようにコードを書くことを許してはいけません。この問題は完全な2泊のために私を驚かせた。 :D –

関連する問題