星空网 > 软件开发 > Java

angularJS配合bootstrap动态加载弹出提示内容

1.bootstrp的弹出提示

  bootstrap已经帮我们封装了非常好用的弹出提示Popover。

  http://v3.bootcss.com/javascript/#popovers

2.自定义popover指令

  我们使用一个指令给任意元素加上popover,并且可以根据情况改变popover的content内容。

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>




原标题:angularJS配合bootstrap动态加载弹出提示内容

关键词:JS

JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流