1

environment

  • AnuglarJS 1.6x
  • ui-bootstrap2.5

I want to display error messages with tool tip on validation with AngularJS. I am referring to the directive created by the following jQuery and bootstrap.js with reference to it, How can I implement it with ui - bootstrap?

Reference sample

I tried trying to add attributes of ui-tooltip at the place where tooltip was set in Query, but it does not work.

<script>
  var app = angular.module("app", ['ui.bootstrap']);
app.controller('Ctrl', function ($scope) {});
app.directive('validationMessage', function () {
    return {
        restrict: 'A',
        priority: 1000,
        require: '^validationTooltip',
        link: function (scope, element, attr, ctrl) {
            ctrl.$addExpression(attr.ngIf || true);
        }
    }
});
app.directive('validationTooltip', function ($timeout) {
    return {
        restrict: 'E',
        transclude: true,
        require: '^form',
        scope: {},
        template: '<span class="label label-danger span1" ng-show="errorCount > 0">hover to show err</span>',
        controller: function ($scope) {
            var expressions = [];
            $scope.errorCount = 0;

            this.$addExpression = function (expr) {
                expressions.push(expr);
            }
            $scope.$watch(function () {
                var count = 0;
                angular.forEach(expressions, function (expr) {
                    if ($scope.$eval(expr)) {
                        ++count;
                    }
                });
                return count;

            }, function (newVal) {
                $scope.errorCount = newVal;
            });

        },
        link: function (scope, element, attr, formController, transcludeFn) {
            scope.$form = formController;

            transcludeFn(scope, function (clone) {

            /
                var badge = element[0].firstChild;
                var tooltip = angular.element('<div class="validationMessageTemplate tooltip-danger" />');
                tooltip.append(clone);
                element.append(tooltip);
                $timeout(function () {


                    scope.$field = formController[attr.target];
                    badge.attr( 'uib-tooltip', "test")

                });
            });
        }

    }
});
Community
  • 1
  • 1
kazunnakam
  • 11
  • 1

0 Answers0