如何使用angularjs在popover中添加字段?

时间:2015-05-29 08:45:54

标签: javascript jquery html angularjs twitter-bootstrap

这是我使用角度js和弹出窗口的代码 我想知道我们如何在custom-popover popover-HTML中添加样式 因为我无法绑定HTML部分中的任何元素



<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
     <script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<div ng-app="customDirectives">
    <div> <span custom-popover popover-html="Some Popover Text"  popover-placement="bottom" popover-label="label"></span>

    </div>
</div>
<script>
customDirectives = angular.module('customDirectives', []);
customDirectives.directive('customPopover', function () {
    return {
        restrict: 'A',
        template: '<span>{{label}}</span>',
        link: function (scope, el, attrs) {
            scope.label = attrs.popoverLabel;
            $(el).popover({
                trigger: 'click',
                html: true,
                content: attrs.popoverHtml,
                placement: attrs.popoverPlacement
            });
        }
    };
});

angular.module('CustomComponents', ['customDirectives']);
</script>
</body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

检查此示例(将popover-some-var添加到您的代码中):

&#13;
&#13;
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
     <script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<div ng-app="customDirectives">
    <div> <span custom-popover popover-html="Some Popover Text"  popover-placement="bottom" popover-label="label" popover-some-var="BLABLABLA"></span>

    </div>
</div>
<script>
customDirectives = angular.module('customDirectives', []);
customDirectives.directive('customPopover', function () {
    return {
        restrict: 'A',
        template: '<span>{{label}}</span>',
        link: function (scope, el, attrs) {
            scope.label = attrs.popoverLabel;
            var someVar = attrs.popoverSomeVar; // HERE IS VARIABLE
            $(el).popover({
                trigger: 'click',
                html: true,
                content: attrs.popoverHtml + " " + someVar,
                placement: attrs.popoverPlacement
            });
        }
    };
});

angular.module('CustomComponents', ['customDirectives']);
</script>
</body>
</html>
&#13;
&#13;
&#13;