인 div
이 있습니다. 그 div
을 클릭하면 지시문에서 스크립트 내용을 가져 오는 함수를 호출하고이를 div
에 추가하고 스크립트의 내용에 액세스합니다. 그러나 지시문의 내용을 검색 할 때 지시문에 내용이 아니라 이름이 지정됩니다. 나는 그 내용을 얻고 싶다.Angular JS : 자바 스크립트 함수에서 지시어 내용을 사용할 수 없습니다.
이 기능은 내가 전화 :
$scope.someFunction = function(){
var appendHtml = $compile("<my-custom-directive></my-custom-directive>")($scope);
$("#someId").append(appendHtml)
//But when i append I am seeing as <my-custom-directive></my-custom-directive> in html not the actual content
$(""#someId"").find('script')
}
지침 :
app.directive('myCustomDirective', function ($compile) {
return {
restrict: 'E',
templateUrl: '/somecontent.html',
replace: true,
link: function ($scope, elem, attr, ctrl) {}
};
});
Somecontent.html
<script type="text/template">
<div class="arrow" style="left: 50%;"></div>
some elements here
</div>
</script>
나는에서 부르는 HTML :
<div ng-click="someFunction()">
<div id="someId">
<my-custom-directive></my-custom-directive>
//But Here I am seeing this, when calling
$(appendHtml).find('script') in my javascript function, after Javasciprt function call is done, It works fine. But i want to see actual content here when calling $(""#someId"").find('script')
<div>
</div>
someFunction이 호출 될 때 필요에 따라 콘텐츠를 가져오고 있습니다. 그래서 당신의 솔루 션이 제 상황에 맞지 않습니다. – emar