無標題文件
<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>