AngularJS自定义指令及指令配置项
2024-08-27 01:08:35
两种写法
//第一种
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";
}]);
最新文章
- SQL Server 多实例下的复制
- Linux系统上通知网关更新arp
- [Leetcode] Recover Binary Search Tree
- pch和info.plist初探
- Android-Opencv开发(一)配置环境
- spring-mvc.xml配置
- JSP+MySQL最简单的登录和注册的实现 --Java Web温习
- php连接mysql...mysqli和mysql
- vivado保存debug波形
- NOIP2018 退役记
- delphi中使用MSWINSCK.OCX控件
- jmeter建立JDBC连接池时遇到“A Test is currently running,stop or shutdown test to execute this command”
- Codeigniter base_url() 返回的怎么是ip地址
- application/json 和 application/x-www-form-urlencoded的区别
- javaScript字符串操作
- 浏览器环境下的javascript DOM对象继承模型
- 最小生成树——Kruscal(克鲁斯卡尔算法)
- java基础之集合:List Set Map的概述以及使用场景
- bzoj 1257 余数之和 —— 数论分块
- BZOJ 1800: [Ahoi2009]fly 飞行棋【暴力】
热门文章
- bug级别分类
- [洛谷P2577] [ZJOI2005]午餐
- map/reduce之间的shuffle,partition,combiner过程的详解
- js中三种定义变量 const, var, let 的区别
- MySQL当中的case when then
- SIFT四部曲之——高斯滤波
- appium===登陆应用的案例
- 自动化测试===uiautomator2类似appium
- python基础===monkeytype可以自动添加注释的模块!
- binlog_server备份binlogs