Home > Article > Web Front-end > Combining angularJS and bootstrap to dynamically load pop-up prompt content_AngularJS
angularjs is an excellent web front-end framework developed by the Google team. With so many web frameworks currently available, angularjs can stand out from the rest in terms of architectural design, two-way data binding, dependency injection, directives, MVC, and templates. Angular.js innovatively integrates back-end technology into front-end development, sweeping away jQuery’s former glory. Using angularjs is like writing backend code, more standardized, more structured, and more controllable.
1.bootstrp pop-up prompt
Bootstrap has helped us encapsulate the very useful pop-up prompt Popover.
http://v3.bootcss.com/javascript/#popovers
2. Custom popover command
We use a command to add a popover to any element, and the popover content can be changed according to the situation.
JS:
<script> var app = angular.module('testApp', []); app.factory('dataService',function() { var service = {}; service.cacheObj = {}; service.getAppName = function (appId, callback) { if (service.cacheObj[appId]) { console.log('get name from cache'); callback(service.cacheObj[appId]); return; } //here is sample. Always ajax. service.cacheObj[appId] = 'QQ'; callback('QQ'); }; return service; }); app.directive('myPopover', function (dataService) { return { restrict: 'AE', link: function (scope, ele, attrs) { $(ele).data('title','App'); $(ele).data('content', "<div id ='popDiv'>Name:-</div>"); $(ele).popover({ html: true, trigger: 'hover'}); $(ele).on('shown.bs.popover',function() { var popDiv = $('#popDiv'); console.log(popDiv); dataService.getAppName('xxx',function(name) { popDiv.html('Name:'+name); }); }); } }; }); app.controller("test",function($scope) { }); </script>
html:
<div ng-app="testApp"> <div ng-controller="test"> <div> <a my-popover>app 1</a> <a my-popover>app 2</a> </div> </div> </div>
The above is the combination of angularJS and bootstrap introduced by the editor to dynamically load pop-up prompt content. I hope you like it.