     link = ($scope, $el, $attrs, $ctrl) ->
         $ctrl.$formatters.push(formatter)
         $ctrl.$parsers.push(parser)
+
+        $scope.$on "$destroy", ->
+            $el.off()
 
     return {
         require: "ngModel"

        </span>
    <% }); %>""")

    renderTags = ($el, tags, editable, tagsColors) ->
        ctx = {
            tags: _.map(tags, (t) -> {name: t, color: tagsColors[t]})
            editable: editable
        }
        html = templateTags(ctx)
        $el.find("div.tags-container").html(html)

    normalizeTags = (tags) ->
        tags = _.map(tags, trim)
        tags = _.map(tags, (x) -> x.toLowerCase())
        return _.uniq(tags)

    link = ($scope, $el, $attrs, $model) ->
        editable = false

        $el.addClass("tags-block")

        addValue = (value) ->
            value = trim(value)

        <span class="icon icon-plus"></span>
        <span class="add-tag-text">Add tag</span>
    </a>
    <input type="text" placeholder="Write tag..." class="tag-input" />
    <a href="" title="Save" class="save icon icon-floppy"></a>
    """

