Hier ist eine Stichprobe der verwendeten Eingangsanweisung
Die Codekopie lautet wie folgt:
<! docType html>
<html>
<kopf>
<meta charset = "utf-8">
<title> bis zum Titel "Dokument" </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">
<Eingabe type = "text" ng-model = "a" test />
<button ng-klick = "anzeigen (a)"> Ansicht </button>
</div>
</body>
<Script>
var app = angular.module ('Demo', [], Angular.noop);
app.directive ('test', function () {<br> // Der Verknüpfung der Eingabeanweisung hat den vierten Parameter, und es gibt einige Methoden von $ ctrl. Sie können ihn selbst verwenden.
var link = function ($ scope, $ element, $ attrs, $ ctrl) {
console.log ($ ctrl)
$ ctrl. $ foratters.push (function (value) {
return value.join (',');
});
$ ctrl. $ parsers.push (function (value) {
return value.split (',');
});
}
return {compile: function () {return link},
erfordern: 'ngmodel',
einschränken: 'a'}
});
app.controller ('testctrl', function ($ scope) {
$ scope.a = [];
//$Scope.a = [1,2,3];
$ scope.show = function (v) {
console.log (v);
}
});
</script>
</html>
Der Code ist sehr einfach, Freunde können ihn frei erweitern, ich hoffe es gefällt euch