29
我是AngularJS的新手,我遇到了一個問題,我遇到了問題,在stackoverflow上有類似的問題,但它似乎沒有幫助我。我基本上有一個通過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;
})
}
非常感謝你,它在約60秒內修好了它。在繼續這個項目之前,我一定會詳細閱讀範圍,因爲我顯然不完全理解它們。 – EvWill
@EvWill很好的解釋,爲什麼它不與我使用原始這裏https://github.com/angular/angular.js/wiki/Understanding-Scopes – Mirko
它錯誤的方式進行一個月以上的工作,非常感謝你。如果這不是正確的方式,那麼Angular不應該允許開發人員以這種方式編寫代碼。這個問題讓我震驚了整整兩個晚上。 :D –