AngularJS를 사용하여 사용자 정의 지시문에서 HTML 기능을 확장하십시오. 사용자 정의 지시문에서 사용하는 "지침"의 기능적 정의. 사용자 정의 지시문은 활성화 된 요소를 대체합니다. 부팅 프로세스 중에 AngularJS 응용 프로그램은 일치하는 요소를 찾아서 하나의 활동에 맞춤 지시 Compile () 메소드를 사용한 다음 명령 범위를 기반으로 사용자 정의 지시문 링크 () 메소드를 사용하여 요소를 처리합니다. AngularJS는 유형의 다음 요소를 갖춘 사용자 정의 지시문을 작성하도록 지원합니다.
요소 지시문 - 지침이 발생할 때 일치하는 요소를 활성화합니다.
속성 --- 지침이 만나면 일치하는 속성을 활성화합니다.
CSS-- 명령이 만나면 일치하는 CSS 스타일을 활성화합니다.
주석 --- 지침이 만나면 일치하는 주석을 활성화합니다.
맞춤 명령을 이해하십시오
사용자 정의 HTML 태그를 정의하십시오.
<학생 이름 = "Mahesh"> </student> <br/>
<학생 이름 = "piyush"> </student>
위의 사용자 정의 HTML 태그를 처리 할 수 있도록 사용자 정의 지침을 정의하십시오.
var mainApp = angular.Module ( "mainApp", []); // 지시 사항을 작성하십시오. 첫 번째 매개 변수는 첨부 할 HTML 요소입니다. // 우리는 학생 HTML 태그를 첨부하고 있습니다. //This directive will be activated as soon as any student element is encountered in htmlmainApp.directive('student', function() { //define the directive object var directive = {}; //restrict = E, signifies that directive is Element directive directive.restrict = 'E'; //template replaces the complete element with its text. directive.template = "Student: <b> {{whient.name}} </b>, 롤 no : <b> {{whient.rollno}} </b> "; // 스코프는 각 학생 요소를 기준에 따라 구별하는 데 사용됩니다. directive.scope = {학생"} // compile은 응용 프로그램을 한 번 호출합니다. 함수 (element.css) ( "국경", "1px solid #cccccc"; <b> "+$ scope.student.rollno+"</b> <br/> "); element.css ("back컨트롤러를 정의하여 범위를 명령어로 업데이트하십시오. 여기서 우리는 이름 속성 값을 어린이의 범위로 사용합니다.
mainApp.controller ( 'StudentController', function ($ scope) {$ scope.mahesh = {}; $ scope.mahesh.name = "mahesh parashar"; $ scope.mahesh.rollno = 1; $ scope.piyush = {}; $ scope.piyush.name = "piyush"; $ scope.piyush.rollno = 2;});예
<html> <head> <title> Angular JS Custom Directives </title> </head> <h2> Angularjs 샘플 응용 프로그램 </h2> <div ng-app = "mainApp"ng-controller = "StudentConTroller"> <student name = "mahesh"> </student> <br/> <brich "> <piyush"> src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"> </script> <cript> var mainApp = Angular.Module ( "mainApp", []); mainApp.directive ( 'Student', function () {var directive = {}; directive.restrict = 'e'; directive.template = "학생 : <b> {{whient.name}}} </b>, roll no : <b> {{indudent.rollno}} </b>"; student.cope (student.cop. attributes) {element.css ( "테두리", "1px solid #cccccccc"); var intrictfunction = 함수 ($ scope, element, attributes) {election.html ( "<b>"+$ scope.student.name+"</b>, <b>"</b> </b. CSS ( "Background-Color", "#ff00ff"} 링크 기능}; mainApp.controller ( 'StudentController', function ($ scope) {$ scope.mahesh = {}; $ scope.mahesh.name = "mahesh parashar"; $ scope.mahesh.rollno = 1; $ scope.piyush = {}; $ scope.piyush.name = "piyush"; $ scope.piyush.rollno = 2); </script> </body> </html>결과
웹 브라우저에서 Open TextAngularjs.html. 결과는 다음과 같습니다.
위의 것은 AngularJS의 사용자 정의 명령 정보를 편집하는 것이며 나중에 계속 추가 할 것입니다. 이 사이트를 지원 해주셔서 감사합니다!