惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
Simon Willison's Weblog
Simon Willison's Weblog
云风的 BLOG
云风的 BLOG
宝玉的分享
宝玉的分享
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Register - Security
The Register - Security
S
SegmentFault 最新的问题
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
量子位
SecWiki News
SecWiki News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 【当耐特】
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Palo Alto Networks Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
爱范儿
爱范儿
S
Secure Thoughts
G
Google Developers Blog
Microsoft Security Blog
Microsoft Security Blog
D
Docker
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
F
Fortinet All Blogs
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
Schneier on Security
Schneier on Security
Y
Y Combinator Blog
博客园 - 三生石上(FineUI控件)
Recent Announcements
Recent Announcements
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
Recorded Future
Recorded Future
罗磊的独立博客
Forbes - Security
Forbes - Security
Security Latest
Security Latest
NISL@THU
NISL@THU
T
The Exploit Database - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
T
Tenable Blog
C
Cybersecurity and Infrastructure Security Agency CISA
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
K
Kaspersky official blog
月光博客
月光博客
小众软件
小众软件
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
WordPress大学
WordPress大学
Security Archives - TechRepublic
Security Archives - TechRepublic

博客园 - 开发手游啦啦啦

用TypeScript开发爬虫程序 ABP导航源码分析 ABP的语言切换 AngularJs自定义指令详解(10) - 执行次序 AngularJs自定义指令详解(9) - terminal AngularJs自定义指令详解(8) - priority AngularJs自定义指令详解(7) - multiElement AngularJs自定义指令详解(6) - controller、require AngularJs自定义指令详解(5) - link AngularJs自定义指令详解(4) - transclude AngularJs自定义指令详解(3) - scope AngularJs自定义指令详解(2) - template ABP的Zero Sample ABP的工作单元 ABP的数据过滤器(Data Filters) ABP的事件总线和领域事件(EventBus & Domain Events) 初入Cocos2d-x 2.2 quick-cocos2d-x之testlua之VisibleRect.lua quick-cocos2d-x之testlua之mainMenu.lua
AngularJs自定义指令详解(1) - restrict
开发手游啦啦啦 · 2015-07-03 · via 博客园 - 开发手游啦啦啦

下面所有例子都使用angular-1.3.16。下载地址:http://cdn.bootcss.com/angular.js/1.3.16/angular.min.js

既然AngularJs快要发布2.0,所以现在也没必要追求最新版本。而且,2.0变动实在太大,所以当前学习AngularJs不需要过度深入。

AngularJs自定义指令时,要求返回一个指令定义对象(Directive Definition Object),该对象可以声明若干属性和方法。下面例子的restrict、template就是其中之一。

restrict是一个可选的参数,若不声明,则取默认值EA。

可选值包括:E(元素)A(属性)C(类名)

混合使用:如:EA,表示既可以作为E也可以作用A。

例子:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <script src="../lib/angular-1.3.16/angular.min.js"></script>
    <script src=""></script>
    <title></title>
    <script language="JavaScript">
        angular.module('app',[])
                .directive('myDirective',function(){
                    return{
                        restrict:'EAC',
                        template:'Hello World!'

                    };
                });
    </script>
</head>
<body ng-app="app">
<my-directive></my-directive>
<div my-directive></div>
<div class="my-directive"></div>
</body>
</html>

在Google Chrome查看:

点击右键-审查元素(或快捷键ctl+shift+i),可以看到:

注意‘Hello World!’字符串的插入位置。