如何使用jquery

时间:2017-01-31 20:44:43

标签: javascript jquery html angularjs

我正在使用角度流星和使用ECMAscript 6类样式编写JS的Web应用程序。我需要将一个元素(稍后会被点击)附加到现有的div中。

我遇到的问题是,当我追加元素时,附加元素的html中包含的角度ng-mouseover指令消失并且不起作用。

我希望新添加的元素监听悬停事件,我找到的唯一解决方案是以某种方式使用$compile。但是,我对Angular非常陌生,并且很难理解$compile文档,特别是在尝试将其转换为ECMAscript可接受的语法时。任何人都可以帮我正确地做到这一点吗?

我尝试通过JQuery附加元素:

$('#progress-container').append("<img src='greenpin.png' ng-click='chat.hovering($event)' id='" + pinId + "' class='pin' style='left: " + pos + "%'/>");

1 个答案:

答案 0 :(得分:1)

使用$ compile可以解决问题!

02-01 21:58:11.908 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.918 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@2d5b7e1e
02-01 21:58:11.918 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.938 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@33cdccc
02-01 21:58:11.938 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.958 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@15bd5e2a
02-01 21:58:11.958 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.978 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@13c0f9b8
02-01 21:58:11.978 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.998 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3aab32f6
02-01 21:58:11.998 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.018 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@c67f964
02-01 21:58:12.018 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.038 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@fcf8882
02-01 21:58:12.038 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.058 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@e5d47d0
02-01 21:58:12.058 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.078 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@26f1aace
02-01 21:58:12.078 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.088 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@201710fc
02-01 21:58:12.088 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.108 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@1501a5da
02-01 21:58:12.108 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.138 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@174240e8
02-01 21:58:12.138 25079-25079/com.theothercard.dragdrop I/ViewRootImpl: Reporting drop result: false