Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Double compiling #15278

Closed
Closed
@ghost

Description

I want that any element with title attribute behaves like an uibTooltip atribute (from UI Bootstrap module). So, I created a simple directive that automatically puts this atribute and removes that other one, like this:

angular.module( 'ui.bootstrap.tooltip' )
  .directive( 'title', function( $compile ) {
    return {
      restrict: 'A',
      link: function( scope, elem, attrs ) {
        attrs.$set( 'uibTooltip', attrs.title );
        $compile( elem.removeAttr( 'title' ) )( scope );
      }
    };
  } );

It converts the attributes and then it compiles again.

The problem appears, for example, in this element (in Bootstrap design):

<div ng-controller="ButtonController as vm">
  <button type="button" class="btn btn-default" title="Add" ng-click="vm.add()"><span class="glyphicon glyphicon-plus"></span></button>
</div>

With appropriate controller:

angular.module( 'app' ) // Whatever name
  .controller( 'ButtonController', function() {
    var vm = this;
    vm.add = function() {
      console.log( 'Added!' );
    }
  } );

Since it recompiles, ngClick function executes twice on click.

Which is the way for change element's attributes before compilation?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions