فيما يلي عينة من تعليمات الإدخال المستخدمة
نسخة الكود كما يلي:
<! doctype html>
<html>
<head>
<meta charset = "utf-8">
<title> Unted Document </title>
</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">
<type type = "text" ng-model = "a" test />
<button ng click = "show (a)"> عرض </button>
</div>
</body>
<script>
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) {
قيمة الإرجاع. join ('،') ؛
}) ؛
$ ctrl. $ parsers.push (function (value) {
قيمة الإرجاع. split ('،') ؛
}) ؛
}
إرجاع {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) ؛
}
}) ؛
</script>
</html>
الكود بسيط للغاية ، يمكن للأصدقاء توسيعه بحرية ، وآمل أن يعجبك