2014-09-05 3 views
1

각도로 다시 만들고 싶은 Jquery의 막대 그래프가 있습니다.div의 너비를 angular.js에서 parent의 백분율로 설정합니다.

$('.item-skills').each(function(){ 
    newWidth = $(this).parent().width() * $(this).data('percent'); 
    $(this).width(newWidth); 
}); 

아래와 같이 그래프가 바로 스타일 화 된 div 이잖아 폭은 내가 생산 것이다

<div bar-graph="0.85"></div> 

처럼 사용하는 bar-graph라는 지시에 넣고 싶은 부모의 비율로 설정되어있다 DIV 그게 전부 폭은 부모의 85 %

편집이다 : 나는 당신이 후입니다 것은 광고 여기 Angularjs adjust width based on parent element width

+0

을 도움이되지만 경우 아래에있는 내 솔루션입니다에서 creating directives에 대한 링크입니다 – Pete

답변

0

다른 사람의 요구가 바 graph` 유효한 속성이되지 않을 것`

(function(angular) { 

     var 
     definitions; 

     definitions = [ 
     niBargraph 
     ]; 

     angular.module('ni.Bargraph').directive('niBargraph', definitions); 

     function niBargraph() { 

     return { 
      scope: { 
      percent: '@niBargraph' 
      }, 
      link: setSize 
     }; 

     function setSize(scope, elm, attrs, ctrl) { 
      elm.css({ 
       width: elm.parent()[0].offsetWidth * parseFloat(scope.percent) 
      }); 
     } 
     } 
    })(angular); 
관련 문제