반응형
Angularjs - 본문 요소 내부 지시어 가져오기
얻는 방법body
각도 지시의 요소? 내 목표는 jquery로 하는 것입니다.$('body').innerWidth();
내부 지시jquery를 사용하는 것이 아니라 각진 내장 jqlite 구현을 사용하고 싶습니다.
다른 요소에 적용되는 지시 내에서 본문 요소에 액세스해야 하는 경우 $document 서비스를 사용할 수 있습니다.
app.directive("myDirective", function($document) {
return function(scope, element, attr) {
var bodyWidth = $document[0].body.clientWidth;
console.log("width of body is "+ bodyWidth);
};
});
<button my-directive>Sample Button</button>
jqLite에서 제공하는 DOM 순회 메서드를 사용할 수도 있습니다(jQuery가 제공하는 것보다 훨씬 덜 강력하지만).예를 들어, 를 사용하여 재귀적 조회를 수행할 수 있습니다.angular.element.parent()
본문 태그를 찾는 방법.
다음을 사용하여 한 가지 변형을 더 합니다.find()
angular의 jQLite에 포함된 구현:
app.directive("myDirective", function() {
return function(scope, element, attr) {
var body = angular.element(document).find('body');
console.log(body[0].offsetWidth);
};
});
언급URL : https://stackoverflow.com/questions/16725136/angularjs-get-body-element-inside-directive
반응형
'source' 카테고리의 다른 글
Linux에서 WaitForSingleObject 및 WaitForMultipleObjects equivalent? (0) | 2023.10.04 |
---|---|
Office 365용 VSTO 추가 기능 (0) | 2023.10.04 |
라라벨:User::의 ID를 가져옵니다. 이 ID를 사용하여 새 행을 만들고 삽입합니다. (0) | 2023.10.04 |
MySQL/MariaDB: 피벗 테이블 뷰로 동적 리포트 생성 (0) | 2023.10.04 |
멀티폼 검증을 위한 저의 요구사항에 맞는 jQuery 플러그인이 있습니까? (0) | 2023.10.04 |