<!doctype html>
<html> <head>
<meta charset="utf-8">
<title>
无标题文档
</title>
<script src="http://localhost:81/js/jquery.js">
</script>
<script src="http://localhost:81/js/angular.min.js">
</script>
</head> <body ng-app="Demo">
<div a>
a_directive
</div>
<div ng-controller="TestCtrl">
<h1 t>
原始内容
</h1>
<h2 t2>
原始内容
</h2>
<h3 t3="hiphop" title2="{{name}}">
原始内容
</h3>
<div compile></div>
<div>
<test a="{{ a }}" b c="xxx"></test> <button ng-click="a=a+1">
修改
</button>
</div>
<te a="1" ys-a="123" ng-click="show(1)">这里</te>
</div>
<script>
var app = angular.module('Demo', [], angular.noop);
app.controller("TestCtrl",
function($scope) {
$scope.name = "qihao";
});
app.directive("t",
function() {
return {
controller : function($scope){$scope.name = "qq"},
template : "<div>test:implementToParent{{name}}</div>",
replace : true,
scope : true //作用域是继承的,默认就是继承的
}
});
app.directive("t2",
function() {
return {
controller : function($scope){$scope.name = "nono"},
template : "<div>test:implementToParent{{name}}</div>",
replace : true,
restrict : "AE"
}
});
app.directive("t3",
function() {
return {
template : "<div>test:implementToParent_titleIs:{{title}}<br>title2Is:{{title2}}</div>",
replace : true,
restrict : "AE",
scope : {
title : "@t3",
title2 : "@title2"
}
}
});
app.directive('a',
function() {
var func = function() {
console.log('compile');
return function() {
console.log('link');
}
} var controller = function($scope, $element, $attrs, $transclude) {
//$transclude :是指令标签的复制体
console.log('controller');
console.log($scope);
console.log($transclude);
//$transclude接受两个参数,你可以对这个克隆的元素进行操作,
var node = $transclude(function(clone_element, scope) {
$element.append(clone_element);
$element.append("<span>spanTag___</span>");
console.log(clone_element);
console.log('--');
console.log(scope);
});
console.log(node);
} return {
compile: func,
template: "<h1 ng-transclude></h1>",
controller: controller,
transclude: true,
restrict: 'AE'
}
});
app.directive('compile',function() {
var func = function() {
console.log('a compile');
return {
pre: function() {
console.log('a link pre')
},
post: function() {
console.log('a link post')
},
}
}
return {
restrict : "AE",
compile : func
}
}) app.directive('test', function(){
var func = function($element, $attrs){
console.log($attrs); $attrs.$observe('a', function(new_v){
console.log(new_v);
});
} return {compile: func,
restrict: 'E'}
}); app.controller('TestCtrl', function($scope){
$scope.a = 123;
}); app.directive('te', function(){
var func = function($scope,$element, $attrs,$ctrl){
console.log($ctrl)
//$attrs.$set. 给这个属性设置b,值为ooo,就是这样
$attrs.$set('b', 'ooo');
$attrs.$set('a-b', '11');
//这个还有点不懂啊 //第二个参数值
$attrs.$set('c-d', '11', true, 'c_d');
console.log($attrs);
} return {
compile: function(){
return func
},
restrict: 'E'
}
}); app.controller('TestCtrl', function($scope){
$scope.show = function(v){console.log(v);}
});
</script>
</body> </html>

  

angular_$attrs的更多相关文章

  1. Android中自定义属性(attrs.xml,TypedArray的使用)

    做Android布局是件很享受的事,这得益于他良好的xml方式.使用xml可以快速有效的为软件定义界面.可是有时候我们总感觉官方定义的一些基本组件不够用,自定义组件就不可避免了.那么如何才能做到像官方 ...

  2. 使用attrs.xml自定义属性

    控件有很多属性,如android:id.android:layout_width.android:layout_height等,但是这些属性都是系统自带的属性.使用attrs.xml文件,可以自己定义 ...

  3. Odoo attrs X2many 类型的过滤

    有童鞋在群里问到 attrs 中的 many2many类型的字段该如何进行domain过滤,其实非常简单: Many2many的字段在js中获取的值的格式为[[6,false,[]]] 所以attrs ...

  4. attrs 中的 uid

        Odoo View视图默认是不认识attrs中的uid的,其原因在于后台将xml转化为html的过程中对attrs调用了python的eval方法,而对于eval函数来说,我们传入的形如[(' ...

  5. 自定义属性,资源文件attrs.xml

    1.attrs.xml中写:在values文件夹下. <?xml version="1.0" encoding="utf-8"?> <reso ...

  6. Android 自定义属性(attrs.xml,TypedArray)

    做Android布局是件很享受的事,这得益于他良好的xml方式.使用xml可以快速有效的为软件定义界面.可是有时候我们总感觉官方定义的一些基本组 件不够用,自定义组件就不可避免了.那么如何才能做到像官 ...

  7. Android中如何利用attrs和styles定义控件

    一直有个问题就是,Android中是如何通过布局文件,就能实现控件效果的不同呢?比如在布局文件中,我设置了一个TextView,给它设置了 textColor,它就能够改变这个TextView的文本的 ...

  8. 关于Android attrs 自定义属性的说明

    写个自定义控件时经常要自定义一些自己的属性,平时用的都是那几个,今天就顺便一起总结一下这个东东吧- 一.定义:属性的定义都在attrs.xml文件里面: 二.读取:通过都是通过TypedArray去读 ...

  9. vue踩坑记录:[Vue warn]: $attrs is readonly.

    今天在用element-ui的DatePicker日期选择器的时候,发现每当点击一次这个组件,控制台就会报警告`[Vue warn]: $attrs is readonly`,但是也不影响实际操作效果 ...

随机推荐

  1. hdu 敌兵布阵(线段树之单点更新)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  2. 10901 Missile

    10901 Missile 时间限制:1000MS  内存限制:65535K提交次数:40 通过次数:7 Description Long, long ago, country A invented ...

  3. [瞎JB写] C++多态

    似乎只能通过引用或者指针进行动态多态...蛋疼的语法 #include <iostream> #include <vector> #include <memory> ...

  4. Shell basic1

    A shell script is a text file that typically begins with a shebang, as follows: #!/bin/bash /bin/bas ...

  5. Hadoop 1.0 和 2.0 中的数据处理框架 - MapReduce

    1. MapReduce - 映射.化简编程模型 1.1 MapReduce 的概念 1.1.1 map 和 reduce 1.1.2 shufftle 和 排序 MapReduce 保证每个 red ...

  6. select2取值报错,Failed to read the 'selectionDirection' property from 'HTMLInputElement': The input element's type ('hidden') does not support selection.

    用到了 select2 组件来多选收件人,用搜狗浏览器(6.2版高速模式)在执行到如下这句时报错(Uncaught InvalidStateError: Failed to read the 'sel ...

  7. Android系列之网络(二)----HTTP请求头与响应头

    ​[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...

  8. TestLink学习五:TestLink1.9.13和JIRA6.3.6的集成

    testlink和jira的集成,一般步骤: 第1步:System-Issue Tracker Management添加JIRA的db模式.第2步:测试项目管理,“Issue Tracker Inte ...

  9. java 13-3 int类型的包装包Integer

    1.Integer的概述 需求1:把100这个数据的二进制,八进制,十六进制计算出来 需求2:判断一个数据是否是int范围内的.  首先你得知道int的范围是多大? 为了对基本数据类型进行更多的操作, ...

  10. java 12-4 StringBuffer类的替换、反转、截取功能

    1.StringBuffer的替换功能: public StringBuffer replace(int start,int end,String str):从start开始到end用str替换 pu ...