<script><br>
var app = angular.module('Demo', [], angular.noop);<br>
app.directive('test', function(){<br> //The link of the input command has a fourth parameter, $ctrl has some methods, you can use it yourself<br>
var link = function($scope, $element, $attrs, $ctrl){<br>
console.log( $ctrl )<br>
$ctrl.$formatters.push(function(value){<br>
return value.join(',');<br>
});<br>
$ctrl.$parsers.push(function(value){<br>
return value.split(',');<br>
});<br>
}<br>
Return {compile: function(){return link},<br>
require: 'ngModel',<br>
restrict: 'A'}<br>
});<br>
app.controller('TestCtrl', function($scope){<br>
$scope.a = [];<br>
//$scope.a = [1,2,3];<br>
$scope.show = function(v){<br>
console.log(v);<br>
}<br>
});<br>
</script>
The code is very simple, friends can expand it freely, I hope you can like it
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn