博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AngularJS directive简述
阅读量:4567 次
发布时间:2019-06-08

本文共 941 字,大约阅读时间需要 3 分钟。

转自:

官方API:

一个民间详细介绍:

问:

angular.module('docsTransclusionExample', []).controller('Controller', ['$scope', function($scope) {  $scope.name = 'Tobias';}]).directive('myDialog', function() {  return {    restrict: 'E',    transclude: true,    scope: {},    templateUrl: 'my-dialog.html',    link: function (scope, element) {      scope.name = 'Jeff';    }  };});

答:

1.restrict E: 表示该directive仅能以element方式使用,即:
A: 表示该directive仅能以attribute方式使用,即:
EA: 表示该directive既能以element方式使用,也能以attribute方式使用 2.transclude 你的directive可能接受页面上的其他html内容时才会用到,建议你先去掉该参数。有些高阶了。 3.scope 当你写上该属性时,就表示这个directive不会从它的controller里继承$scope对象,而是会重新创建一个。 4.templateUrl 你的directive里的html内容 5.link 可以简单理解为,当directive被angular 编译后,执行该方法

这里你说的没错,link中的第一个参数scope基本上就是你说的上面写的那个scope

element简单说就是$('my-dialog')

attrs是个map,内容是你这个directive上的所有属性,例如:你在页面上如果这样写了directive:

attrs就是:

{type: 'modal',animation: 'fade'}

 

转载于:https://www.cnblogs.com/golddream/p/5015989.html

你可能感兴趣的文章
jquery和dom元素相互转换
查看>>
放大的X--HDOJ-201307292012
查看>>
题目831-签到-nyoj-20140818
查看>>
百词斩-斩家秘籍
查看>>
php反射
查看>>
hdu 1018 Big Number 数学结论
查看>>
【MUI】百度地图定位功能
查看>>
bzoj3687 简单题
查看>>
STL容器简介
查看>>
HashMap遍历的两种方式,推荐使用entrySet()
查看>>
如何在Android开发中测试应用在真机上实验
查看>>
传奇代码研究 极品机率...
查看>>
(转)park1.0.0生态圈一览
查看>>
需要学习双拼了
查看>>
Apache Spark大数据分析入门(一)
查看>>
java8使用stream的collect进行list转map注意事项
查看>>
部分和问题
查看>>
进程,线程
查看>>
[。。。]不知道是事故还是故事的东西
查看>>
AtCoder Beginner Contest 073
查看>>