2013-10-11 4 views
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; 
    }) 
} 

답변

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

와 자바 스크립트에

, 아약스 콜백에로 변경 할 문제 : 참조 : 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

한 달 이상 잘못 사용했습니다. 정말 고마워요. 이것이 올바른 방법이 아니라면, Angular는 devs가 코드를 그렇게 쓰는 것을 허용해서는 안됩니다. 이 문제는 완전한 2 박 동안 나를 두려워했다. : D –

관련 문제