


Written in front: Since the directive part is the top priority in angularjs, it will be explained in multiple chapters. This chapter mainly explains the simpler attributes in the object returned by directive
Directive() is used in angularjs to define instructions. This method receives two parameters: name (the name of the instruction), factory_function (this function defines all the behaviors of the instruction and returns an object)
Chestnut:
//index.js angular.module('myApp',[]); myApp.directive('myDirective',function() {return {};});
The returned object contains the following properties and methods:
1: restrict: String
This attribute is used to describe the form in which the myDirective directive is declared in the DOM (that is, where it should be used in HTML)
The optional values of this attribute are: E (element), A (attribute, default value), C (class name), M (comment), which can be used alone or in combination
I have seen a saying: If you want to customize an independent command function, that is, the command can complete a series of operations independently without relying on other elements, attributes, etc., then define the command as an element; if you want to use this command To extend the functionality of an existing directive, define it as an attribute. I don’t know if this understanding is reasonable, but it is indeed a good selection method standard that can be used for reference
2: priority: Number
This attribute is used to define the priority of the instruction (the default is 0, ngRepeat has the highest priority among all built-in instructions, which is 1000). The one with higher priority is executed first.
3: terminal: Boolean
This attribute is related to the priority attribute. It is used to determine whether to stop running instructions with a lower priority than this instruction on the current element, but the same priority will still be executed
Chestnut:
//index.js angular.module('myApp',[]) .directive('myDirective',function() { return { restrict: 'AE', priority: 1, template: '<div>hello world</div>' }; }) .directive('myDirective1',function() { return { restrict: 'AE', priority: 3, terminal: true }; })
<!-- index.html --> <div my-directive my-directive1></div>
If the myDirective1 directive is not defined, the browser will display hello world, but after adding the myDirective1 directive, setting its priority to be greater than myDirective, and setting the terminal attribute to true on myDirective1, it will stop. Execution of myDirective directive.
4: template: String/Function
This attribute defines a template (that is, the part using this instruction in the html file will replace the content of the template, so the template is mainly in html format)
Attributes come in two forms: a piece of html text, and a function that returns a template string, and the function receives two parameters: tElement, tAttrs
5: templateUrl: String/Function
When there is a lot of template content, nesting it directly in the template will appear redundant. You can store the template code in a separate file. In this case, you will need to import the file. TemplateUrl can do this
Attributes also come in two forms: a string representing the path of an external html file, and a function that returns a string of the path to an external html file. This function receives two parameters: tElement, tAttrs
6: replace: Boolean
The default value of this attribute is false, indicating whether the template will be inserted as a child element into the element that calls this directive, or overwrite and replace the element that calls this directive.
Chestnut:
//index.js angular.module('myApp',[]) .directive('myDirective',function() { return { restrict: 'A', template: '<div>hello world</div>', replace: true/false }; })
<!-- index.html --> <my-directive></my-directive>
When repalce is false, the browser source code is rendered as
When true, it will appear as
7: transclude: Boolean
Chestnut:
<!-- index.html --> <div my-directive>world</div>
Like this example, if there is content inside the instruction, usually the template will directly overwrite and replace the content, but now I want to keep it, and this is where transclude comes in handy
//index.js angular.module('myApp',[]) .dirctive('myDirective',function() { return { restrict: 'EA', transclude: true, template: '<div>hello <span ng-transclude></span></div>' }; })
The above js code will embed the world contained in the html file directive into the span element in the template. Note that the span element adds the ng-transclude built-in directive attribute (this is very important)
In short, the purpose of this attribute is to tell the angularjs compiler to put the content it gets from the DOM element where it finds the ng-transclude directive.
The above is the entire content of this article, I hope it will be helpful to everyone's study.

Javascript 是一个非常有个性的语言. 无论是从代码的组织, 还是代码的编程范式, 还是面向对象理论都独具一格. 而很早就在争论的Javascript 是不是面向对象语言这个问题, 显然已有答案. 但是, 即使 Javascript 叱咤风云二十年, 如果想要看懂 jQuery, Angularjs, 甚至是 React 等流行框架, 观看《黑马云课堂JavaScript 高级框架设计视频教程》就对了。

在如今信息时代,网站已经成为人们获取信息和交流的重要工具。一个响应式的网站能够适应各种设备,为用户提供优质的体验,成为了现代网站开发的热点。本篇文章将介绍如何使用PHP和AngularJS搭建一个响应式网站,从而提供优质的用户体验。PHP介绍PHP是一种开源的服务器端编程语言,非常适用于Web开发。PHP具有很多优点,如易于学习、跨平台、丰富的工具库、开发效

随着互联网的不断发展,Web应用已成为企业信息化建设的重要组成部分,也是现代化工作的必要手段。为了使Web应用能够便于开发、维护和扩展,开发人员需要选择适合自己开发需求的技术框架和编程语言。PHP和AngularJS是两种非常流行的Web开发技术,它们分别是服务器端和客户端的解决方案,通过结合使用可以大大提高Web应用的开发效率和使用体验。PHP的优势PHP

随着互联网的普及,越来越多的人在使用网络进行文件传输和共享。然而,由于各种原因,使用传统的FTP等方式进行文件管理无法满足现代用户的需求。因此,建立一个易用、高效、安全的在线文件管理平台已成为了一种趋势。本文介绍的在线文件管理平台,基于PHP和AngularJS,能够方便地进行文件上传、下载、编辑、删除等操作,并且提供了一系列强大的功能,例如文件共享、搜索、

随着Web应用程序的普及,前端框架AngularJS变得越来越受欢迎。AngularJS是一个由Google开发的JavaScript框架,它可以帮助你构建具有动态Web应用程序功能的Web应用程序。另一方面,对于后端编程,PHP是非常受欢迎的编程语言。如果您正在使用PHP进行服务器端编程,那么结合AngularJS使用PHP将可以为您的网站带来更多的动态效

随着Web技术的飞速发展,单页Web应用程序(SinglePageApplication,SPA)已经成为一种越来越流行的Web应用程序模型。相比于传统的多页Web应用程序,SPA的最大优势在于用户感受更加流畅,同时服务器端的计算压力也大幅减少。在本文中,我们将介绍如何使用Flask和AngularJS构建一个简单的SPA。Flask是一款轻量级的Py

随着互联网的普及和发展,前端开发已变得越来越重要。作为前端开发人员,我们需要了解并掌握各种开发工具和技术。其中,PHP和AngularJS是两种非常有用和流行的工具。在本文中,我们将介绍如何使用这两种工具进行前端开发。一、PHP介绍PHP是一种流行的开源服务器端脚本语言,它适用于Web开发,可以在Web服务器和各种操作系统上运行。PHP的优点是简单、快速、便


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
