纳克单击动态绑定

纳克单击动态绑定

本文介绍了纳克单击动态绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户需要一定的行动,我插入一个链接到CONTENTEDITABLE字段的文本:

When a user takes a certain action, I insert a link into the text of a contenteditable field:

var newElement = document.createElement('span');
newElement.innerHTML = "<a id='123' class='cite' href='' data-ng-click='review(123);'>[&#8225;]</span>";
range.insertNode(newElement);
$compile($(newElement).contents())($scope);

当用户点击onthe新的领域,我要执行的激活控制器的复习方法。 ($ scope.review =功能(ID){...};)

When the user clicks onthe new field, I want to execute the review method of the activate controller. ($scope.review = function(id) {...};)

而不是页面导航到'#',而不调用审查();

Instead the page navigates to '#', without calling review();

我assuing点击方法没有得到通过向range.insertNode(为newElement)调用绑定至$ scope.review(); ?我试图包裹在$适用,但没有奏效。

I am assuing the click method doesn't get 'bound' to $scope.review() by a call to range.insertNode(newElement); ? I tried wrapping in an $apply, but that didn't work.

推荐答案

使用的href =而不是的href =#与角度。默认的动作始终是$ pvented如果href为空P- $。

Use href="" instead of href="#" with Angular. The default action is always prevented if the href is empty. http://docs.angularjs.org/api/ng.directive:a

另外,还要确保该元素。理想的情况是,如果你正在做的是这将是情况基本上使元素列表

Also make sure to $compile that element. Ideally this would be a case for ng-repeat if what you're doing is essentially making a list of elements.

这篇关于纳克单击动态绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 17:18