angularjs学习之六(angularjs中directive指令的一般编程事件绑定 模板使用等)
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指令的一般编程事件绑定 模板使用等)的更多相关文章
- Angularjs学习---ubuntu12.04中karma安装配置
Angularjs学习---ubuntu12.04中karma安装配置中常见的问题总结 karma启动时出现了很多问题: 1.安装karma前提条件 安装karma首先要安装nodejs,npm然 ...
- MVVM设计模式和WPF中的实现(四)事件绑定
MVVM设计模式和在WPF中的实现(四) 事件绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM设计模式和在WPF中的实现(四) 事件绑定
系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中的实现(三)命令绑定 MVVM模式解析和在WPF中的 ...
- AngularJS中Directive指令系列 - 基本用法
参考: https://docs.angularjs.org/api/ng/service/$compile http://www.zouyesheng.com/angular.html Direct ...
- angularjs中directive指令与component组件有什么区别?
壹 ❀ 引 我在前面花了两篇博客分别系统化介绍了angularjs中的directive指令与component组件,当然directive也能实现组件这点毋庸置疑.在了解完两者后,即便我们知道co ...
- 《AngularJS权威教程》中关于指令双向数据绑定的理解
在<AngularJS权威教程>中,自定义指令和DOM双向数据绑定有一个在线demo,网址:http://jsbin.com/IteNita/1/edit?html,js,output,具 ...
- angularjs学习笔记3-directive中scope的绑定修饰符
在angularjs中,一个directive返回一个对象,对象存在很多属性,并且可以在directive中自定义自己的scope,而使用自己的scope是为了防止一个directive被使用在多个地 ...
- AngularJs学习——何时应该使用Directive、Controller、Service?
翻译:大漠穷秋 原文链接:http://kirkbushell.me/when-to-use-directives-controllers-or-services-in-angular/ 一.简述 A ...
- angularjs学习总结一(表达式、指令、模型)
一:自执行匿名函数 (function(){ /*code*/})();自执行匿名函数:常见格式:(function() { /* code */ })();解释:包围函数(function(){}) ...
随机推荐
- TP框架中同时使用“or”和“and”
今天在tp中遇到一个问题,可能这并不算难的问题,但是我还是分享一下 以下是tp手册里面查询or的方式 $User = M("User"); // 实例化User对象 $where[ ...
- centos7 rsync+inotify软件实现集群服务的数据备份(一)
一.rsync软件的说明: 1.1 什么是rsync rsync是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.它使用所谓的“Rsync演算法”来使本地和远程两个主机之间的文件达 ...
- 开发语言之---Python
Python,如果你想进军AI,或是不想被自动化运维淘汰,Python是一门必须课. 在未来的大学课堂上,也许也会将Python加入必修中,就像Java一样. Python之“Hello World” ...
- 【HDU 1402】A * B Problem Plus(FFT)
Problem Description Calculate A * B. Input Each line will contain two integers A and B. Process to e ...
- Spring☞WebApplicationContext的继承关系
spring mvc里的root/child WebApplicationContext的继承关系 在传统的spring mvc程序里会有两个WebApplicationContext,一个是pare ...
- [luoguP2073] 送花(set)
传送门 set #include <set> #include <cstdio> #include <iostream> #define LL long long ...
- [luoguP1273] 有线电视网(DP)
传送门 f[i][j]表示节点i选j个用户的最大收益 #include <cstdio> #include <cstring> #include <iostream> ...
- selenide01---截图
1.junit:import com.codeborne.selenide.junit.ScreenShooter; @Rule public ScreenShooter makeScreenshot ...
- 2016 ACM/ICPC 区域赛(北京) E 题 bfs
https://vjudge.net/problem/UVALive-7672 题意 输入一个五位数n 问由12345变到n的操作最少次数 不可达输出-1 有三种操作 1.交换相邻的位置 次数不 ...
- The Bottom of a Graph
poj——The Bottom of a Graph Time Limit: 3000MS Memory Limit: 65536K ...