angular js 中模板的使用。事件绑定以及指令与指令之间的交互

相应教学视频地址(需翻墙):

v=aG8VD0KvUw4">angularjs教学视频

<!doctype html>
<html ng-app="myapp">
<head>
<meta charset="utf-8"/>
</head>
<body ng-controller="ShieldController">
<div>
<who></who>
</div>
<div>
<button you-btn></button>
</div>
<theshield reigns>343</theshield>
<theshield reigns>fdhg</theshield>
<theshield rollins>hhh</theshield>
<theshield ambros>kkk</theshield>
</body>
<script src="./js/angular.min.js"></script>
<script>
var app = angular.module('myapp',[]); /*=======================1. 模板的使用 ========================*/
app.directive('who',function(){
return {
restrict:"E", //元素element 的意思
link:function(scope,element,attrs){
console.log(element);
element[0].innerHTML = 'sdfhkj'; //这个优先级别最高
},
//templateUrl:"param.html", //这个不显示 优先级别最低
template:"<h1>jkdhf</h1>" //这个显示 优先级别其次
};
}); /*=======================2. 事件的绑定 ========================*/
app.directive('youBtn',function(){
return {
restrict:"A", //attribute 属性的意思
link:function(scope,element,attrs){
console.log(element);
element[0].innerHTML = 'my btn';
//事件绑定
element.bind('mouseenter',function(){
element[0].innerHTML = 'your btn';
});
element.bind('mouseleave',function(){
element[0].innerHTML = 'her btn';
});
}
};
}); /*=======================3. 元素 属性 控制器之间的交互========================*/ app.controller('ShieldController',function($scope){
$scope.shieldNames = [];
this.addReigns = function(){
$scope.shieldNames.push("reigns:jjj");
}
this.addRollins = function(){
$scope.shieldNames.push("Rollins:hhh");
}
this.addAmbros = function(){
$scope.shieldNames.push("Ambros:ggg");
}
})
.directive('reigns',function(){
return {
require:"theshield",
link:function(scope,element,attrs,ShieldController){
ShieldController.addReigns();
}
};
})
.directive('rollins',function(){
return {
require:"theshield",
link:function(scope,element,attrs,ShieldController){
ShieldController.addRollins();
}
};
})
.directive('ambros',function(){
return {
require:"theshield",
link:function(scope,element,attrs,ShieldController){
ShieldController.addAmbros();
}
};
})
.directive('theshield',function(){
return {
restrict:"E",
controller:"ShieldController", //指定控制器
scope:{}, //清空该指令处的$scope 值
link:function(scope,element,attrs){
element.bind('mouseenter',function(){ //对于该指令所相应的元素绑定相应的事件
console.log(scope.shieldNames);
});
}
};
}); </script>
</html>

angularjs学习之六(angularjs中directive指令的一般编程事件绑定 模板使用等)的更多相关文章

  1. Angularjs学习---ubuntu12.04中karma安装配置

    Angularjs学习---ubuntu12.04中karma安装配置中常见的问题总结   karma启动时出现了很多问题: 1.安装karma前提条件 安装karma首先要安装nodejs,npm然 ...

  2. MVVM设计模式和WPF中的实现(四)事件绑定

    MVVM设计模式和在WPF中的实现(四) 事件绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  3. MVVM设计模式和在WPF中的实现(四) 事件绑定

    系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中的实现(三)命令绑定 MVVM模式解析和在WPF中的 ...

  4. AngularJS中Directive指令系列 - 基本用法

    参考: https://docs.angularjs.org/api/ng/service/$compile http://www.zouyesheng.com/angular.html Direct ...

  5. angularjs中directive指令与component组件有什么区别?

     壹 ❀ 引 我在前面花了两篇博客分别系统化介绍了angularjs中的directive指令与component组件,当然directive也能实现组件这点毋庸置疑.在了解完两者后,即便我们知道co ...

  6. 《AngularJS权威教程》中关于指令双向数据绑定的理解

    在<AngularJS权威教程>中,自定义指令和DOM双向数据绑定有一个在线demo,网址:http://jsbin.com/IteNita/1/edit?html,js,output,具 ...

  7. angularjs学习笔记3-directive中scope的绑定修饰符

    在angularjs中,一个directive返回一个对象,对象存在很多属性,并且可以在directive中自定义自己的scope,而使用自己的scope是为了防止一个directive被使用在多个地 ...

  8. AngularJs学习——何时应该使用Directive、Controller、Service?

    翻译:大漠穷秋 原文链接:http://kirkbushell.me/when-to-use-directives-controllers-or-services-in-angular/ 一.简述 A ...

  9. angularjs学习总结一(表达式、指令、模型)

    一:自执行匿名函数 (function(){ /*code*/})();自执行匿名函数:常见格式:(function() { /* code */ })();解释:包围函数(function(){}) ...

随机推荐

  1. POJ-3278 抓住这头牛

    广搜解决. 广搜搜出最短路,直接输出返回就行了. 每个点只搜一次,而且界限进行一次判断. else 语句里面不要用if    else if,这样的话就直走一条路了. #include <ios ...

  2. 厚溥教育1718部数据库连接作业答案,分装一个操作数据库而无需写SQL语句的函数

    <?php header("Content-type:text/html;charset=utf8"); //PHP操作数据库的函数 function phpsql($dbc ...

  3. git服务器端安装

    一.服务器端安装 git支持四种传输协议 1.本地协议 2.ssh协议 3.git协议 4.http/s协议 [root@zabbix ~]# cat /etc/redhat-release Cent ...

  4. 第一讲:vcs simulation basic

    要求: 1.complie a verilog/systemverilog design using vcs 2.simulate a verilog/systemverilog design vcs ...

  5. 如何将数据放入下拉框List值

    最近在做下拉框,里面放入值大概有这几种 //仓库业务类型 第一种 model.addAttribute("warehouseBizTypeList", basePropertySe ...

  6. 发布tomcate时报A configuration error occurred during startup.please verify the preference field with the prompat:null

    发布tomcate时报A configuration error occurred during startup.please verify the preference field with the ...

  7. Sublime Text 3使用方法

    一.下载安装 Sbulime Text 3官网   参考网站:http://lucida.me/blog/sublime-text-complete-guide/注意在安装时勾选Add to expl ...

  8. python3--产生偏移和元素:enumerate

    之前,我们讨论过通过range来产生字符串中元素的偏移值.而不是那些偏移值处的元素.不过,在有些程序中.我们两者都需要,要用的元素以及值个元素的偏移值.从传统意义来讲,这是简单的for循环,他同时也持 ...

  9. [Go]接口的运用

    在Go语言中,不能通过调用new函数或make函数创建初一个接口类型的值,也无法用字面量来表示一个接口类型的值.可以通过关键字type和interface声明接口类型,接口类型的类型字面量与结构体类型 ...

  10. 【Kubernetes】kube-dns 持续重启

    kuberbetes部署和启动正常,但是kube-dns持续重启 使用命令 kubectl get pods --all-namespaces 得到结果 从图中可以看出kube-dns-c7d8589 ...