Popover Template in Angular UI

元气小坏坏 提交于 2020-01-02 02:19:07

问题


I am using angular-ui-bootstrap in my current project, and I have a requirement for a popover to open up in each row in a grid displaying row specific information. The popover should have its own HTML template and there are multiple fields that can be bound in the HTML template. Here is the code I have written to achieve the same. I did try to pass the html template with no luck. Any help is appreciated.

HTML Code:

<div ng-app="helloAngular" ng-controller="casesCntrl">
  <table class="table table-bordered">
    <thead>
      <tr>
        <th class="">Date</th>
        <th class="">Case</th>                    
        <th class="">Severity</th>                
        <th class="">Status</th>
        <th class="">Site</th>
      </tr>
    </thead>
    <tbody>
      <tr ng-repeat="case in cases">
        <td>{{case.casedate | date:'MM/dd/yyyy'}}</td>  
        <td><a ng-href="#/site/{{case.id}}">{{case.name}}</a></td>
        <td ng-class="{'case-critical':case.severity==1, 'case-urgent':case.severity==2, 'case-normal':case.severity==3}"  class="case-none"></td>  
        <td>{{case.status}}</td>    
        <td>{{case.sitename}}&nbsp;<button popover="{{case.sitename}}" popover-title="{{case.sitedescription}}"  data-placement="bottom" data-trigger="focus" class="btn btn-default" popover-unsafe-html="This is a Help but please <b> focus </b> on this">V</button></td>    
      </tr>
    </tbody>
  </table>      
</div>

JS Code:

function CasesController($scope) {    

var casesData = [
  {

    "name": "Case -1",
    "casedate":"2013-06-26T08:02:00-0700",
    "caseid":1,
    "severity": "1",
    "status":"New",
    "siteid":1,
    "sitename":"Merchant Demo 1"
  },
  {
    "name": "Case -2",
    "casedate":"2013-01-26T08:02:00-0700",
    "caseid":2,
    "severity": "1",
    "status":"New",
    "siteid":2,
    "sitename":"Merchant Demo 2"
  },
  {
    "name": "Case -3",
    "casedate":"2013-02-26T08:02:00-0700",
    "caseid":3,
    "severity": "1",
    "status":"Accepted",
    "siteid":1,
    "sitename":"Merchant Demo 3"
  } ,
  {
    "name": "Case -4",
    "casedate":"2013-05-26T08:02:00-0700",
    "caseid":4,
    "severity": "2",
    "status":"New",
    "siteid":1,
    "sitename":"Merchant Demo 4"
  } ,
  {
    "name": "Case -5",
    "casedate":"2013-09-26T08:02:00-0700",
    "caseid":5,
    "severity": "3",
    "status":"New",
    "siteid":1,
    "sitename":"Merchant Demo 5"
  } ,
  {
    "name": "Case -6",
    "casedate":"2013-04-26T08:02:00-0700",
    "caseid":6,
    "severity": "1",
    "status":"Sent to billing",
    "siteid":1,
    "sitename":"Merchant Demo 6"
  },
  {
    "name": "Case -7",
    "casedate":"2013-10-26T08:02:00-0700",
    "caseid":7,
    "severity": "3",
    "status":"New",
    "siteid":1,
    "sitename":"Merchant Demo 7"
  }
 ];
$scope.cases = casesData;
}

Here is the fiddle that has the same code as described above: http://jsfiddle.net/anirbankundu/YyK5s/4/

I did try the option by passing popover-unsafe-html as described in https://github.com/angular-ui/bootstrap/pull/641


回答1:


Can't be done right now, check the following issue for more details: https://github.com/angular-ui/bootstrap/issues/220

You can how ever use angular-strap to achieve the thing. Details are available at: http://mgcrea.github.io/angular-strap/##popovers




回答2:


The functionality to provide a template to a popover is introduced in angular UI bootsrap version 0.13.0 using popover-template attribute which takes the location of a template to use for the popover body. http://angular-ui.github.io/bootstrap/#/popover




回答3:


The open issue referenced by Faisal Feroz on angular-ui has been closed and added to version 0.13.0 of the framework, so now this is possible. Take a look at https://github.com/angular-ui/bootstrap/issues/220



来源:https://stackoverflow.com/questions/21982204/popover-template-in-angular-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!