2014-09-04 5 views
0

국가의 이름을 입력 한 다음 글로벌 변수를 덮어 쓰는 양식이 있습니다. 제출 단추는 클릭 할 때 아무 것도하지 않습니다. 나는 어디에서 실종 되었습니까? 다음은 HTML입니다Angularjs 양식이 작동하지 않습니다.

<div ng-controller="InputController"> 
     <form class="form-wrapper cf" role="form"> 
      <input type="text" ng-model="model.country" placeholder="Search country..." required> 
      <button type="submit" ng-click="update()">Search</button> 
      <span>{{model.country}} ======</span> 
     </form> 
    </div> 

여기 컨트롤러가 있습니다.

LastFmApp.controller('InputController', 
function InputController($scope) { 
    $scope.model = {}; 
    $scope.update = function() { 
     console.log($scope.model.country); 
    }; 
}); 
+0

잘 작동하는 것 같습니다. http://plnkr.co/edit/4j4bJurfxcMPOkXMHIiT?p=preview – JoseM

답변

0

나는 각도 j와 관련이 있다고 생각하지 않습니다. 제출 단추는 페이지를 다시로드하므로 모델에서 변경 사항을 볼 수 없습니다.

<input type="button" ng-click="update()">Search</input > 

또는 입력 유형은 양식에 ngSubmit 속성으로 제출 :

당신은 ngClick로 입력 유형 버튼을 사용할 수 있습니다 내가 생각 해달라고

<form ng-submit="update()"> 
    <input type="submit">Search</input> 
</form> 
0

어떤 문제는 거기 당신의 코드 see 코드가 플 런커에서 작동 중임

<div ng-controller="InputController"> 
     <form class="form-wrapper cf" role="form"> 
      <input type="text" ng-model="model.country" placeholder="Search country..." required> 
      <button type="submit" ng-click="update()">Search</button> 
      <span>{{model.country}} ======</span> 
     </form> 
    </div> 

http://plnkr.co/edit/u9hqu1bASxxMgtEP1qAr?p=preview

관련 문제