无标题文档
<script><br />
var app = angular.module('Demo', [], angular.noop);<br />
app.directive('test', function(){<br> //input 指令的 link有第四个参数,$ctrl有些方法,你可以自己拿来用<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>