Вот образец используемой инструкции ввода
Кода -копия выглядит следующим образом:
<! Doctype html>
<html>
<голова>
<meta charset = "utf-8">
<title> unt назвал документ </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">
<input type = "text" ng-model = "a" test />
<Кнопка ng-click = "show (a)"> View </button>
</div>
</body>
<Скрипт>
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 (function (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);
}
});
</script>
</html>
Код очень прост, друзья могут свободно расширить его, надеюсь, вам это понравится