Home  >  Article  >  Web Front-end  >  How to use angular’s ​​custom directives

How to use angular’s ​​custom directives

php中世界最好的语言
php中世界最好的语言Original
2018-03-16 17:15:171512browse

This time I will show you how to use angular's custom instructions. What are the precautions when using angular's custom instructions. The following is a practical case, let's take a look.

Customized specification

angular.module('dir',[  ]).directive( 'mydir' ,function(  ){   return {template:'
hello
'}} )

Customized specification extends the attributes of the original html.

Specified application:

写成自定义属性 ----A----属性 -写成元素。注意如果需要改变模板路径里面的内容,就需要使用ng-transclude,然后在模板指令的配置项里写 return {templateUrl :../template.html,transclued:true} -----E----元素

You can write templateUrl(scope:{footer:@footer}) in the configuration item (note that footer in the element tag in @footer is an attribute ),

Error: $compile:iscp
Invalid Isolate Scope Definition
Description
When declaring isolate scope the scope definition object must be in specific format which starts with mode character (@&=<), after which comes an optional ?, and it ends with an optional local name.
myModule.directive('directiveName', function factory() {  return {
    ...
    scope: {      'localName': '@', // OK
      'localName2': '&attr', // OK
      'localName3': '

Multiple words in the directive use camel case naming ('myDir'). You can use my-dir to write instructions in html, because html is not case-sensitive.
-- replace: true in templateUrl(scope:{footer:@footer}, replace:true) can replace the custom-specified tag.

The form of the specified class: a2cdb136a79469197e61a7b5adbc122716b28748ea4df4d9c2150843fecfba68, but because the default is A||E, a matching mode configuration item needs to be added:
templateUrl (scope:{footer:@footer}, restrict:C) can be added successfully. ------Category C------

There are four matching modes in total: A, C, E, M (Comment , less commonly used), if not Write the matching pattern, the default is A || E.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

$watch, $apply and $digest data binding process detailed explanation

javascript must-have detailed explanation

What are the built-in objects of js

The above is the detailed content of How to use angular’s ​​custom directives. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn