난 당신이 뭔가를 사용할 수 있다고 생각 자바 스크립트 측면에서 전체 문장
<ul ng-repeat='sentence in list'>
<li><span the-dir txt="sentence"></span></li>
</ul>
, 그것은 매우 간단하지만, 더 이상이다 :
.directive('theDir', function($compile){
var r=/(social security)/ig;
return {
scope:{txt:'='},
link:function(scope,element,attributes){
scope.aFunction=function(){
console.log('In the directive, you clicked on social security');
}
if(r.test(scope.txt)) {
splitted=scope.txt.split(r);
console.log(splitted)
var newSpan=new angular.element('<span>');
for(var i=0;i<splitted.length;i++)
{
if(r.test(splitted[i])){
var newLink=new angular.element('<a>');
newLink.attr('ng-click','aFunction()');
newLink.addClass('social-security');
newLink.html(splitted[i]);
newSpan.append(newLink);
}
else
newSpan.append(splitted[i]);
}
element.append(newSpan);
$compile(newSpan)(scope);
}
else
{
element.html(scope.txt);
}
}
}
});
정규 표현식을 사용하여 '사회 보장'문장을 모두 찾고,이 경우 전체 문장을 분리 한 다음 각 angular.element (이 경우 HTML 링크, ng- 클릭 속성). 모든 정규 단어와 원래 요소에 대한 링크를 추가 한 다음 작동 링크가있는 새로 작성한 기간을 $ n 컴파일하여 컴파일합니다.
는 그리고 난 당신이 코드를 먹자, 내가
재미
을 가지고 당신에게
도움이되기를 바랍니다
을 작동하는 것 같다