简体   繁体   English

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

[英]how to add fields in popover using angularjs?

This is my code for popover using angular js and I want to know that how we can add our styling in custom-popover popover-HTML as I am not able to bind any element in the HTML part 这是我使用angular js进行popover的代码,我想知道我们如何在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> 

Check this example (added popover-some-var to Your code) : 检查以下示例(将popover-some-var添加到您的代码中):

 <!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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM