2017-02-02 1 views
0

는 말 각도 응용 프로그램 이벤트에서 메서드를 호출? 그리고 메소드 선언을 어디에 두겠습니까? 컨트롤러에서, 어쩌면? 내가 AngularJS와 새로운, 그래서 부드러운 주시기 바랍니다 :)나는이 방법이

답변

0

이것은 아주 기본적인 각 응용 프로그램 설치가 doThings() 함수 호출과 같습니다 표준 방법은 꽤 많이 있습니다. 근무 예 : http://www.w3schools.com/angular/default.asp

:

var app = angular.module('myApp', []); 
 

 
app.controller('myCtrl', function($scope) { 
 
    $scope.doThings = function() { 
 
    alert('I do some things!'); 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 

 
<div ng-app="myApp" ng-controller="myCtrl"> 
 
    <input type="button" value="Click Me" ng-click="doThings()" /> 
 
</div>

W3 스쿨에 좋은 튜토리얼이 있습니다

0

당신이 내재 된 첨부 파일 이름이 지정된 함수 중 하나 $scope 또는 컨트롤러의 뷰 모델 변수, 그 것이다 하지 화재 때문에.

... 당신이 $scope에 바인딩하거나 것, 그것은 화재

$scope.doThings = doThings; 

을 ... 또는는 VM 변수에 정의하고 다음보기에서 것을 를 호출합니다.

var vm = this; 
vm.doThings = doThings; 

// HTML 
// assuming your controller is bound to vm through its directive 
// or through ng-controller="Controller as vm" 

<input type="button" value="Click Me" ng-click={{vm.doThings()}}> 
관련 문제