gpt4 book ai didi

angularjs - 无法破坏 Angular 带弹出框

转载 作者:行者123 更新时间:2023-12-03 01:36:05 25 4
gpt4 key购买 nike

我正在使用 $popover 服务使用 Angular-strap 创建弹出窗口,如下所示:

this.popover = $popover(this.element, {
title: 'popover title',
content: 'popover content',
trigger: 'hover',
container: 'body',
html: true
});

这会正确呈现:

enter image description here

但是,当我尝试销毁弹出窗口时,它并没有完全删除它,因为当我将鼠标悬停在该元素上时,它会显示以下内容:

enter image description here

我已经分别尝试了以下两行代码,它们产生了相同的空弹出窗口结果:

this.popover.destroy();

this.popover.$scope.$destroy();

我做错了什么?

最佳答案

我尝试过,它对我来说工作得很好,你可以在这里引用plnkr:http://plnkr.co/edit/KyioKkQhxZDfUnQ0jn2E?p=preview

//HTML 代码

<!DOCTYPE html>
<html ng-app="mgcrea.ngStrapDocs">

<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/fontawesome/4.3.0/css/font-awesome.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="//mgcrea.github.io/angular-strap/styles/libs.min.css">
<link rel="stylesheet" href="//mgcrea.github.io/angular-strap/styles/docs.min.css">
<link rel="stylesheet" href="style.css" />
<script src="//cdn.jsdelivr.net/angularjs/1.4.5/angular.min.js" data-semver="1.4.5"></script>
<script src="//cdn.jsdelivr.net/angularjs/1.4.5/angular-animate.min.js" data-semver="1.4.5"></script>
<script src="//cdn.jsdelivr.net/angularjs/1.4.5/angular-sanitize.min.js" data-semver="1.4.5"></script>
<script src="//mgcrea.github.io/angular-strap/dist/angular-strap.js" data-semver="v2.3.7"></script>
<script src="//mgcrea.github.io/angular-strap/dist/angular-strap.tpl.js" data-semver="v2.3.7"></script>
<script src="//mgcrea.github.io/angular-strap/docs/angular-strap.docs.tpl.js" data-semver="v2.3.7"></script>
<script src="script.js"></script>
</head>

<body ng-controller="MainCtrl">

<div class="bs-docs-section" ng-controller="PopoverDemoCtrl">


<div class="bs-example" style="padding-bottom: 24px;" append-source>

<!-- A popover can also be triggered programmatically using the $popover service -->
<button type="button" id="popover-as-service" class="btn btn-lg btn-primary" title="{{popover.title}}" ng-click="togglePopover()">Click to toggle popover
<br />
<small>(using $popover service)</small>
</button>
<div><a ng-click="hidePopover()">Click to close</a></div>

</div>


</div> </body>

</html>

//JS代码

var app = angular.module('mgcrea.ngStrapDocs', ['ngAnimate', 'ngSanitize', 'mgcrea.ngStrap']);

app.controller('MainCtrl', function($scope) {
});

'use strict';

angular.module('mgcrea.ngStrapDocs')

.config(function($popoverProvider) {
angular.extend($popoverProvider.defaults, {
html: true
});
})

.controller('PopoverDemoCtrl', function($scope, $popover) {

$scope.popover = {title: 'Title', content: 'Hello Popover<br />This is a multiline message!'};

var asAServiceOptions = {
title: $scope.popover.title,
content: $scope.popover.content,
trigger: 'manual'
}

var myPopover = $popover(angular.element(document.querySelector('#popover-as-service')), asAServiceOptions);
console.log(myPopover);

$scope.togglePopover = function() {
myPopover.$scope.$show();

};
$scope.hidePopover = function() {
myPopover.destroy();

};
});

或者,如果您仍然面临一些问题,您可以创建一个 plnkr 并分享。

关于angularjs - 无法破坏 Angular 带弹出框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36008442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com