This is my Directive. which display one Div on the body.
app.directive("autosuggest", function($rootScope) {
return {
scope: {
doneFlag : "=",
groupFlag : "=",
inviteesFlag : "=",
init: '&'
},
templateUrl : "title.html",
link: function(scope, element, attrs) {
}
});
And in title.html
<div class="showw">
<img id="hideDivOnClick" src="ddd.png"/>
</div>
And i include directive like this
<div autosuggest="" done-Flag="1" group-Flag="1" invitees-Flag="1" selected-Array="" ></div>
so when i click on image then this <div autosuggest="" done-Flag="1" group-Flag="1" invitees-Flag="1" selected-Array="" ></div>
parts gets remove from body. like remove element in Javascript. how i will achive this in angularJS?
Here the task is to remove a particular element from the DOM with the help of AngularJS. Approach: Here first we select the element that we want to remove. Then we use remove() method to remove that particular element.
HTML DOM Element remove() The remove() method removes an element (or node) from the document.
Select the HTML element which need to remove. Use JavaScript remove() and removeChild() method to remove the element from the HTML document.
Use the removeChild() or remove() method to remove an element from the DOM.
For clearing/removing html elements, we can use the following methods
var myEl = angular.element( document.querySelector( '#divID' ) );
myEl.empty(); //clears contents
var myEl = angular.element( document.querySelector( '#divID' ) );
myEl.remove(); //removes element
Reference : http://blog.sodhanalibrary.com/2014/08/empty-or-remove-element-using-angularjs.html#.Vd0_6vmqqkp
Use below in your directive.
Directive
app.directive("removeMe", function() {
return {
link:function(scope,element,attrs)
{
element.bind("click",function() {
element.remove();
});
}
}
});
HTML
<div class="showw" remove-me>
<img id="hideDivOnClick" src="ddd.png"/>
</div>
Working Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With