简体   繁体   中英

how to use angluarJS to get the parent element when a button is clicked?

I am actually trying to use angular to use ajax and it's something like deleting comments / posts.

I searched online and there are lots of tutorials then I figured how the tutorial was doing would refresh the page.

I know if I am doing this by using jQuery that I can just use something like $(this).parent().remove() or something similar to remove the element from the dom without refreshing and the backend will do it's job. But with angular js, how can I say something such as $(this).parent().remove() .

I tried console.log the above it returns something weird, like m{ $$ChildScope : b() $$childHead : b $$childTail : b $$listenerCount : Object $$listeners : Object $$nextSibling : null $$prevSibling : null $$watchers : Array[5]

and so one.

Can someone please give me a hand?

Thanks in advance.

Following example will remove whole <div> when button is clicked.

<div ng-if="removed">
   <span>Hello</span>        
   <button ng-click="removed=true">Remove me</button>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM