I have some form and div in bootstrap modal, when click on div it will add some css class to change the look, and input something in the form, now when I close the modal and open it again the form input and added css class is still there, I want whenever the modal is open, it should be a new one. So I find a solution:
$('#modal).on('hidden',function(){
$(this).removeData('modal')
})
The idea is that Bootstrap will instantiate an modal first time the modal() fired, and add some data-modal to the modal element, and when next modal() fires, it just show the hidden old modal instance, not create new one, so the above method try to delete the data-modal attributes and force the Bootstrap to instantiate an new modal.
But it seems won't work in angular, here is what I have:
<div class='row' >
<div class='span14' >
<div data-new-modal='new_item_modal' id='new_item' class='item' >create</div>
</div>
</div>
<div id='new-item-modal' data-item-modal>
// modal body
</div>
angular
directive.newItem = function(){
return {
restrict:'A',
link:function(scope,element,attrs){
element.bind('click',function(){
$('#'+attrs.newItem).modal();
});
}
};
};
directive.itemModal = function(){
return {
restrict:'A',
link:function(scope,element,attrs){
element.on('hidden',function(){
console.log(element.data('modal'))
element.removeData('modal') // wont work
//scope.$apply(element.removeData('modal')) wont work either
console.log(element.data('modal'))
})
}
}
};
Any idea How to reset bootstrap modal in angular?
And I just find out even if I refresh the page the sometime the modal still stay the same!