먼저 렌더링을 살펴 보겠습니다
우선, 지시 중첩에 대해 이야기합시다. 이름에서 알 수 있듯이 지시 중첩은 다음과 같은 두 가지 이상의 지시 사항이 함께 중첩되었음을 의미합니다.
<A-Deirective> <B-Directive> </b-directive> <c-directive> </c-directive> </a-directive>
다음 탭 함수 명령이 사용되어 코드를 더 간결하게 만들 수 있습니다.
<! docType html> <html lang = "en"ng-app = "docstabsexample"> <head> <meta charset = "utf-8"> <title> </title> <script> </script> <script src = "lib/angular.min.js"type/javascript "> src = "lib/angular-route.js"type = "text/javaScript> </script> <script src ="lib/jquery-2.4.min.js "> </script> <script src ="lib/bootstrap.js "type ="text/javascript "> href = "css/bootstrap.css"type = "text/css"/> <style> .Active {배경 : 빨간색; } </style> </head> <body ng-controller = "appcon"> <my-tabs> <!-외부 명령-> <my-pane title = "one"> <!-내부 명령-> <h4> one </h4> <p> angularangularangular </my-pane> <my-pane> <! <H4> Two </h4> <p> Angularangularangularangularangularangularangular </p> </my-pane> <my-pane thit <H4> 5 </h4> <p>jqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqu eryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjqueryjquery</p> </my-tabs> </body> <cript> var app = angular.module ( "docStabsexample", [ 'template']) .controller ( "AppCon", [ "$ scope", function ($ scope) {}]) .Directive ( "myTabs", function () {retain {retain : "e,"in ", scope :}, templateUrl : "mytabs.html", 컨트롤러 : [ "$ scope", function ($ scope) {// 컨트롤러를 사용하여 내부 명령어가 외부 명령을 상속받을 수 있도록 내부 계층이 범위 전도 var var panes = $ scope.scopes = [// $ scope = funtect (pane)를 통해 외부 명령을 전달할 수 있도록합니다. angular.foreach (panes, function (scope) {// 모든 메모리 지침 범위를 전송하고 균일하게 내용을 숨 깁니다. scope.selected = false;}); if (panes.length === 0) {$ scope.select (scope); // 내부 명령 배열을 외부 명령 스코프 배열로 전달합니다. '^mytabs', // 외부 명령 템플릿을 상속합니다 : "mypane.html", 링크 : 함수 (Scope, elemenet, attrs, mytabscontroller) {mytabscontroller.addscope (scope); // OUTER 지시 사항을 저장합니다)). Angular.Module ( "Template", []) .Run ([ "$ templateCache", function ($ templateCache) {$ templatecache.put ( "myTabs.html", "<div class = 'table'>" + "<ul class = 'nav-tabs'>" + "<li ng-repeat = 'pane in scopes' ng-class = '{active : pane.selected}'> " +"<a href = '#'ng-click = 'select (pane)'> {{pane.tittle}}} <a/> " +"</li> " +"</ul> " +"<div ng-transclude class = 'tab-content'> </div> ")))). .Run ([ "$ templatecache", function ($ templatecache) {$ templatecache.put ( "myPane.html", "<div class = 'table-pane'ng-show = 'selected'ng-transclude>" + "</div>") </html> 전체 명령의 구현 원칙은 지시 상속을 통해 내부 명령의 scope 외부 명령에 노출시켜 내부 명령의 표시를 외부 명령으로 제어 할 수 있도록하는 것입니다. 여기에 설명 할 또 다른 사항이 있습니다. 지침을보다 계층적이고 논리적으로 만들기 위해 ng-transclude 지침의 template 내용을 ng-transclude 로 표시된 컨텐츠로 반전 될 수 있도록 사용됩니다.
결론
자, 위의 내용은 지침을 통해 탭 전환 기능을 구현하는 AngularJS에 관한 것입니다. 배웠습니까? Angularjs를 배우는 것이 도움이되기를 바랍니다. 궁금한 점이 있으면 의사 소통을 위해 메시지를 남길 수 있습니다. Wulin.com을 지원 해주셔서 감사합니다.