两种写法

//第一种
angular.module('MyApp',[])
.directive('zl1',zl1)
.controller('con1',['$scope',func1]); function zl1(){
var directive={
restrict:'AEC',
template:'this is the it-first directive',
};
return directive;
}; function func1($scope){
$scope.name="alice";
} //第二种
angular.module('myApp',[]).directive('zl1',[ function(){
return {
restrict:'AE',
template:'thirective',
link:function($scope,elm,attr,controller){
console.log("这是link");
},
controller:function($scope,$element,$attrs){
console.log("这是con");
}
};
}]).controller('Con1',['$scope',function($scope){
$scope.name="aliceqqq";
}]);

指令配置项

angular.module('myApp', []).directive('first', [ function(){
return {
// scope: false, // 默认值,共享父级作用域
// controller: function($scope, $element, $attrs, $transclude) {},
restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment
template: 'first name:{{name}}',
};
}]).directive('second', [ function(){
return {
scope: true, // 继承父级作用域并创建指令自己的作用域
// controller: function($scope, $element, $attrs, $transclude) {},
restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment
//当修改这里的name时,second会在自己的作用域中新建一个name变量,与父级作用域中的
// name相对独立,所以再修改父级中的name对second中的name就不会有影响了
template: 'second name:{{name}}',
};
}]).directive('third', [ function(){
return {
scope: {}, // 创建指令自己的独立作用域,与父级毫无关系
// controller: function($scope, $element, $attrs, $transclude) {},
restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment
template: 'third name:{{name}}',
};
}])
.controller('DirectiveController', ['$scope', function($scope){
$scope.name="mike";
}]);

最新文章

  1. SQL Server 多实例下的复制
  2. Linux系统上通知网关更新arp
  3. [Leetcode] Recover Binary Search Tree
  4. pch和info.plist初探
  5. Android-Opencv开发(一)配置环境
  6. spring-mvc.xml配置
  7. JSP+MySQL最简单的登录和注册的实现 --Java Web温习
  8. php连接mysql...mysqli和mysql
  9. vivado保存debug波形
  10. NOIP2018 退役记
  11. delphi中使用MSWINSCK.OCX控件
  12. jmeter建立JDBC连接池时遇到“A Test is currently running,stop or shutdown test to execute this command”
  13. Codeigniter base_url() 返回的怎么是ip地址
  14. application/json 和 application/x-www-form-urlencoded的区别
  15. javaScript字符串操作
  16. 浏览器环境下的javascript DOM对象继承模型
  17. 最小生成树——Kruscal(克鲁斯卡尔算法)
  18. java基础之集合:List Set Map的概述以及使用场景
  19. bzoj 1257 余数之和 —— 数论分块
  20. BZOJ 1800: [Ahoi2009]fly 飞行棋【暴力】

热门文章

  1. bug级别分类
  2. [洛谷P2577] [ZJOI2005]午餐
  3. map/reduce之间的shuffle,partition,combiner过程的详解
  4. js中三种定义变量 const, var, let 的区别
  5. MySQL当中的case when then
  6. SIFT四部曲之——高斯滤波
  7. appium===登陆应用的案例
  8. 自动化测试===uiautomator2类似appium
  9. python基础===monkeytype可以自动添加注释的模块!
  10. binlog_server备份binlogs