다음은 사용 된 입력 명령어의 샘플입니다
코드 사본은 다음과 같습니다.
<! doctype html>
<html>
<헤드>
<meta charset = "utf-8">
<title> 제목의 문서 </title>
</head>
<script src = "http : // localhost : 81/js/jquery.js">
</스크립트>
<script src = "http : // localhost : 81/js/angular.min.js">
</스크립트>
<body ng-app = "데모">
<div ng-controller = "testctrl">
<입력 유형 = "text"ng-model = "a"test />
<버튼 ng-click = "show (a)">보기 </button>
</div>
</body>
<cript>
var app = angular.module ( 'demo', [], angular.noop);
app.directive ( 'test', function () {<br> // 입력 지시의 링크에는 네 번째 매개 변수가 있으며 $ ctrl의 몇 가지 방법이 있습니다. 직접 사용할 수 있습니다.
var link = function ($ scope, $ element, $ attrs, $ ctrl) {
Console.log ($ ctrl)
$ ctrl. $ formatters.push (function (value) {
return value.join ( ',');
});
$ ctrl. $ parsers.push (함수 (value) {
return value.split ( ',');
});
}
return {compile : function () {return link},
필요 : 'ngmodel',
제한 : 'a'}
});
app.controller ( 'testctrl', function ($ scope) {
$ scope.a = [];
//$scope.a = [1,2,3];
$ scope.show = function (v) {
Console.log (V);
}
});
</스크립트>
</html>
코드는 매우 간단합니다. 친구는 자유롭게 확장 할 수 있습니다.