在AngularJs中,使用jQuery添加dom对象来使用数据双向绑定失效。

在AngularJs中,使用jQuery添加dom对象来使用数据双向绑定失效。

 $(document).on("click", ".typeWrapper .pItem, .typeWrapper .cItem, .typeWrapper .nItem", function(e) {

            e.stopPropagation();

            $scope.tree.Type = $(this).find(">span").html();

            $scope.typeList = false;

            $scope.$apply();

 })

如果AngularJs不能检测到对于model的修改,则需要手动调用$apply()。



动态创建HTML追加到页面相对应的容器,添加点击事件失败,由于jQuery版本不同, 对应的解决方法也不同。

1. 使用$(document).on("click", ".typeWrapper .pItem, .typeWrapper .cItem, .typeWrapper .nItem", function() {  });

2. 使用$(".typeWrapper .pItem").live('click', function() {  });

3. 使用$(".typeWrapper .pItem").on('click',  function() {  });

你可能感兴趣的:(在AngularJs中,使用jQuery添加dom对象来使用数据双向绑定失效。)