您的位置:首页 > Web前端 > AngularJS

url变化的时候,modal框没有消失

2016-05-12 17:18 639 查看
使用angularjs和bootstrap中。如果url变化,modal框不会主动消失,因此,使用directive来控制。

.directive('discardModal', ['$rootScope', '$modalStack',
function($rootScope, $modalStack) {
return {
restrict: 'A',
link: function() {
/**
* If you are using ui-router, use $stateChangeStart method otherwise use $locationChangeStart
* StateChangeStart will trigger as soon as the user clicks browser back button or keyboard backspace and modal will be removed from modal stack
*/

$rootScope.$on('$locationChangeStart', function (event) {
var top = $modalStack.getTop();
if (top) {
$modalStack.dismiss(top.key);
}
});
}
};
}
]);

html代码
<div class="add-config-modal" discard-modal>
//modal内容
</div>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  angularjs bootstrap