이 기사에서는 JS를 사용하여 앵글 컨트롤러의 기능 또는 변수를 외부에서 호출하는 것에 대해 설명합니다. 다음과 같이 참조에 대해 공유하십시오.
<! doctype html> <html ng-app = "myapp"id = "myapp"> <head> <head> <meta name = "viewport"content = "width = device-width"/> <title> test> <script src = "~/컨텐츠/js/js/plugins/angularjs/angular.min.js"> ng-controller = "myController"> {{msg}} <a href = "javaScript :;" id = "lbtntest"> call </a> </a> </body> </html> <cript> var ngapp = angular.module ( 'myapp', []); ngapp.controller ( 'myController', function ($ scope, $ http) {$ scope.msg = 'Hello, Angular!'; $ scope.getData = function () {return 'qubernet';}}); onload = function () {docut // $ scope variable var $ scope = angular.element (applement) .scope (); // msg 변수를 호출하고 msg $ scope.msg = '123456'의 값을 변경합니다. // 이전 줄은 MSG의 값을 변경했습니다. Angular Controller와 동기화하려면 $ apply () 메소드, $ scope. $ apply (); // 컨트롤러 console.log에서 getData () 메소드를 호출합니다 ($ scope.getData ()); }} </script>효과는 "호출"버튼을 클릭하기 전에 아래 그림에 나와 있습니다.
"호출"버튼을 클릭 한 후 효과는 다음 그림에 표시됩니다.
이 기사가 모든 사람의 AngularJS 프로그래밍에 도움이되기를 바랍니다.