Angularjs 템플릿 내에서 재사용 가능한 스 니펫을 수행 할 수 있습니까?

StackOverflow https://stackoverflow.com//questions/12698796

  •  12-12-2019
  •  | 
  •  

문제

코드의 동일한 코드를 반복해서 반복하는 것을 찾아내는 것입니다. angularjs :

에서 같은 것을 할 수 있습니다.
<div ng-snippet="mySnippet"> 
  This is a snippet 
</div> 

<div ng-snippet="anotherSnippet"> 
  Yet another snippet!!
</div>

<ng:include src="anotherSnippet">
<ng:include src="anotherSnippet">
<ng:include src="mySnippet">
.

및 위의 출력은 다음과 같습니다.

Yet another snippet!!
Yet another snippet!!
This is a snippet
.

나는이 정확한 "ng : 포함"솔루션이나 패턴을 반드시 찾는 것이 아니라 내 템플릿에서 반복을 줄일 수있는 것입니다.

도움이 되었습니까?

해결책

<script type='text/ng-template' id="mySnippet"> 
    This is a snippet 
</script> 

<script type='text/ng-template' id="anotherSnippet"> 
    Yet another snippet!!
</script>

<ng-include src="'anotherSnippet'"></ng-include>
<ng-include src="'anotherSnippet'"></ng-include>
<ng-include src="'mySnippet'"></ng-include>
.

이것은 당신이 원하는 것이 여야합니다.

스크립트 NG-include .

다른 팁

이 소리는 지시문 를 사용하려는 것과 같습니다.다음은 간단한 예입니다. http://jsfiddle.net/gyf6v/1/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top