[angularjs] directive compile로 원하는 형태로 변경하기

angularjs에 directive라는 유용한 기능이 있다. 

directive가 생성되는 과정에는 compile과 link라는 과정을 거치게 되는데, 

compile에 경우 scope와는 상관없이 html에 대한 element 속성만 변경이 가능하다. 


예를 들면 아래와 같이 반복되면서 파라미터 객체만 달리해야하는 html 태그가 있을때 사용하면 유용하다. 


<input type="text" ng-click="test(name)" ng-change="test(name)" ng-hover="test(name)"


위와 같이 반복되는 html tag를 아래와 같이 디렉티브를 사용하여 쉽게 사용할수 있다. 


<customTag param="name"></customTag>



자세한 샘플코드는 아래 plunker에서 확인하도록 하자. 

http://plnkr.co/edit/cJgfVG?p=info