Berikut adalah sampel instruksi input yang digunakan
Salinan kode adalah sebagai berikut:
<! Doctype html>
<Html>
<head>
<meta charset = "UTF-8">
<title> unt judul dokumen </iteme>
</head>
<Script src = "http: // localhost: 81/js/jQuery.js">
</script>
<Script src = "http: // localhost: 81/js/angular.min.js">
</script>
<body ng-app = "demo">
<Div ng-controller = "testctrl">
<input type = "text" ng-model = "a" test />
<tombol ng-click = "show (a)"> Lihat </button>
</div>
</body>
<script>
var app = angular.module ('demo', [], angular.noop);
app.directive ('test', function () {<br> // Tautan dari Petunjuk Input memiliki parameter keempat, dan ada beberapa metode $ CTRL, Anda dapat menggunakannya sendiri.
var link = fungsi ($ scope, $ element, $ attrs, $ ctrl) {
Console.log ($ Ctrl)
$ ctrl. $ formatters.push (function (value) {
value return.join (',');
});
$ ctrl. $ parsers.push (function (value) {
return value.split (',');
});
}
return {compile: function () {return link},
membutuhkan: 'ngmodel',
Batasi: 'a'}
});
app.controller ('testctrl', function ($ scope) {
$ scope.a = [];
//$scope.a = [1,2,3];
$ scope.show = function (v) {
console.log (v);
}
});
</script>
</html>
Kode ini sangat sederhana, teman dapat memperluasnya dengan bebas, saya harap Anda menyukainya