นี่คือตัวอย่างของคำสั่งอินพุตที่ใช้
การคัดลอกรหัสมีดังนี้:
<! doctype html>
<html>
<head>
<meta charset = "utf-8">
<tite> เอกสารชื่อ 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">
<อินพุต type = "text" ng-model = "a" ทดสอบ />
<button ng-click = "show (a)"> ดู </button>
</div>
</body>
<script>
var app = angular.module ('demo', [], Angular.noop);
app.directive ('ทดสอบ', function () {<br> // ลิงก์ของคำสั่งอินพุตมีพารามิเตอร์ที่สี่และมีวิธีการบางอย่างของ $ ctrl คุณสามารถใช้เองได้
var link = function ($ scope, $ element, $ attrs, $ ctrl) {
console.log ($ ctrl)
$ ctrl. $ formatters.push (ฟังก์ชั่น (ค่า) {
return value.join (',');
-
$ ctrl. $ parsers.push (ฟังก์ชั่น (ค่า) {
return value.split (',');
-
-
return {compile: function () {return link}
ต้องการ: 'ngmodel'
จำกัด : 'a'}
-
app.controller ('testctrl', ฟังก์ชั่น ($ scope) {
$ scope.a = [];
//$scope.a = [1,2,3];
$ scope.show = function (v) {
console.log (v);
-
-
</script>
</html>
รหัสนั้นง่ายมากเพื่อนสามารถขยายได้อย่างอิสระฉันหวังว่าคุณจะชอบมัน