sourcecode

ng-model이 텍스트 입력 후 업데이트되지 않음

codebag 2023. 3. 9. 22:03
반응형

ng-model이 텍스트 입력 후 업데이트되지 않음

Angular는 처음입니다.JS와 저는 문제가 있어서 스택오버플로우에도 비슷한 질문이 있었지만 도움이 되지 않는 것 같습니다.기본적으로는 ng클릭으로 갱신되는 폼이 있는데 텍스트 상자에 텍스트를 입력하면 해당 텍스트 상자가 갱신되지 않습니다.

이것은 나의 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;
  })
}

링크에 로그인이 필요합니다.

당신의 문제를 추측해야 한다면, 그것은 각도 범위 문제와 관련이 있을 수 있습니다.대신 ng-model 바인딩을 오브젝트 속성으로 변경해 보십시오.따라서 html에 다음 대신 입력:

<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 콜백에서 다음과 같이 변경합니다.

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

이 문제에 대한 자세한 내용은http://https://github.com/angular/angular.js/wiki/Understanding-Scopes 를 참조해 주세요.

언급URL : https://stackoverflow.com/questions/19310129/ng-model-no-longer-updates-after-typing-into-text-input

반응형