简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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