2017-12-03 7 views
0

code-prettify를 사용하여 특정 줄을 색칠하려고합니다. 백엔드에서 줄 번호와 관련하여 데이터를 가져오고 강조 표시하려고합니다. 나는 내 CSS 파일이 쓰기 경우 작동이 잘되는아이디로 각도 번호를 사용하여 nth-child에 액세스하기

#file2 li:nth-child(n+1):nth-child(-n+11) { 
     background: #18b478; 
    } 

. 하지만, 각도를 사용하여이를 구현하는 방법을 이해할 수 없습니다. 여기서 내가 얻고있는 줄 번호에 따라 CSS에 동적으로 변경을 가하고 싶습니다. 이것은 내가 시도 것입니다 :

$("#file2 li:nth-child(n+1):nth-child(-n+11)").css('background', "#18b478"); 

이 내 HTML 코드입니다 :

<div class="container" style="margin-bottom: 50px"> 
<div class="col-sm-6"> 
    <pre> 
     <code class="prettyprint linenums" id="file1">***some code***</code> 
    </pre> 
</div> 
+0

각도를 사용하는 것은 일반적으로 jQuery를 사용하지 않는다는 것을 의미합니다. – charlietfl

+0

희망 li : nth-child (n + 1) 모든 li을 선택하십시오. 이 선택기에 대해 조금 혼란스러워합니다! –

답변

0

는 배열 라인 색상을 상상해보십시오. (줄 수의 길이로) 그리고 다른 줄에 줄이있다. 코드에서

$scope.lines = linesarray 
$scope.colors = colorsarray 

<pre> 
    <code ng-repeat="line in $scope.lines"> 
     Line content: {{ line }} 
     Line number is: {{ $index }} 
     Associated color is: {{ colors[$index] }} 
    </code> 
    //make use of the $index that returns current index of the ng-repeat loop 
</pre> 

희망이 도움이!