0

I have an angularJS app which is leveraging bootstrap UI. I'm trying to set up some bootstrap tooltips, which have a large number of configurable elements. Rather than making my markup significantly larger than I'd prefer, I'd like to push the options into my controller.

The current markup looks something like this:

<p tooltip-placement="right" tooltip="{{bic.multipleIncomeTooltip()}}" tooltip-animation="true" tooltip-trigger tooltip-enable="bic.model.borrowers[bic.borrowerIndex()].income.hasMultipleEmployments"></p>

I would prefer to push the options for this into my controller, so the markup can be simplified to something like this:

<p tooltip-options="bic.incomeTooltipOptions" />

Is there a way to do this?

1
  • 1
    you can create your own directive, and put the current markup as a template, then make "tooltip-options" as a default paramter, which bind to a controller variable. Say your directive named "yourTooltip", then your html will be <div your-tooltip="bic.incomeTooltipOptions" /></div> Commented Feb 15, 2017 at 19:35

1 Answer 1

0

Yes, create your own directive that uses that markup and then pass all the values you need

html

<p tooltip-options="tooltipObject"></p>

js

angular.module('app', [])
.directive('tooltipOptions', function() {
    return {
        restrict: 'A',
        replace: true,
        controller: ['$scope', function($scope) {
        }],
        template: '<p tooltip-placement="tooltipOptions.placement" tooltip-animation="tooltipOptions.animation"></p>',
        scope: {
          tooltipOptions: '='
        }
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.