Ievgen
Ievgen

Reputation: 8086

Angular with Bootstrap popovers. How to apply bindings in generated popover's body?

I want to use bootstrap popovers as dialogs.

    <a popover href="#" 
        data-toggle="popover" title="" 
        data-html="true" 
        data-content=
           "<p>Are you sure? {{contact.FirstName}} will be removed!</p>
            <button class='btn'>Yes</button>
            <button ng-click='cancel()' class='btn'>Cancel</button>" 
        data-original-title="Remove Contact">Remove</a>

JS:

var ang = angular.module("ang", []);

ang.controller("angCtrl", function($scope) {
    $scope.contact = {
            Id: 1,
            FirstName: "John",
            LastName: "Doe"
        };

    $scope.cancel = function() {
        console.log('Cancel called');
    };
});

ang.directive("popover", function() {
    return {
        restrict: "A",
        link: function (scope) {
            scope.$watch("contacts", function () {
                $("a[data-toggle=popover]")
                .popover()
                .click(function (e) {
                    e.preventDefault();
                });
            });
        }
    };
});

The problem is bootarap generates popover html after angular has applied its bindings. How can I include a new generated popover?

Thanks in advance!

Upvotes: 2

Views: 18908

Answers (2)

Ievgen
Ievgen

Reputation: 8086

http://mgcrea.github.io/angular-strap/#/popover Popover directives/popover.js

Fetches an external html partial (or an inline ng-template) and populates the popover with its content.

Upvotes: 2

Ahmad Alfy
Ahmad Alfy

Reputation: 13371

For inconsistencies like this, consider using Angular directives for Twitter's Bootstrap. This might not answer your question, but it will make your life easier.

I ran into a few problems like this when I tried to use Bootstrap with Angular so I decided to move to the mentioned directives and it solved all troubles.

Upvotes: 0

Related Questions