angularjs transclude demo
<!doctype html>
<html lang="en" ng-app="expanderModule">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="lib/angular.js"></script>
<style>
.expander{border:solid 1px black;width: 250px;}
.expander>.title{background-color: black;color: white;padding: .1em .3em; cursor: pointer;}
.expander>.body{padding: .1em .3em;}
</style>
</head>
<body>
<div ng-controller="SomeController">
<expander class="expander" expander-title="title">
{{title}}
</expander>
</div>
<script>
var app = angular.module('expanderModule', []);
app.controller('SomeController', function ($scope) {
$scope.title = '点击展开';
$scope.text = 'This is section !'
})
.directive('expander', function () {
return {
restrict: 'EA',
replace: true,
transclude: true,
scope: {
title: '=expanderTitle'
},
template: '<div><div class="title" ng-click="toggle()">{{title}}</div><div class="body" ng-show="showMe" ng-transclude></div></div>',
link: function (scope, element, attrs) {
scope.showMe = false;
scope.toggle = function () {
scope.showMe = !scope.showMe;
}
}
}
});
</script>
</body>
</html>
<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="lib/angular.js"></script>
<style>
.expander{border:solid 1px black;width: 250px;}
.expander>.title{background: black;color: white;padding: .1em .3em;cursor: pointer;}
.expander>.body{padding: .1em .3em;}
</style>
</head>
<body ng-controller="SomeController">
<accordion>
<expander class="expander" ng-repeat="expander in expanders" expander-title="expander.title">
{{expander.text}}
</expander>
</accordion>
<script>
var app = angular.module('myApp', []); app.directive('accordion', function () {
return {
restrict: 'EA',
replace: true,
transclude: true,
template: '<div ng-transclude></div>',
controller: function () {
var expanders = [];
this.gotOpened = function (selectedExpander) {
angular.forEach(expanders, function (expander) {
if (selectedExpander != expander) {
expander.showMe = false;
};
});
}
this.addExpander = function (expander) {
expanders.push(expander);
}
}
}
});
app.directive('expander', function () {
return {
restrict: 'EA',
replace: true,
transclude: true,
require: '^?accordion',
scope: {
title: '=expanderTitle'
},
template: '<div><div class="title" ng-click="toggle()">{{title}}</div><div class="body" ng-show="showMe" ng-transclude></div></div>',
link: function (scope, element, attrs, accordionController) {
scope.showMe = false;
accordionController.addExpander(scope);
scope.toggle = function toggle() {
scope.showMe = !scope.showMe;
accordionController.gotOpened(scope);
}
}
}
});
app.controller('SomeController', function ($scope) {
$scope.expanders = [{title: 'Click me to expand', text: 'Hi there folks, I am the content that was hidden but is now shown.'}, {title: 'Click this', text: 'I am even better text than you have seen previously'}, {title: 'Test', text: 'test'}];
})
</script>
</body>
</html>
angularjs transclude demo的更多相关文章
- AngularJS入门-demo
双向绑定测试: <body ng-app> 请输入姓名:<input ng-model="myname"> <br> {{myname}},你好 ...
- angularJS transclude
参考来源:彻底弄懂AngularJS中的transclusion 对以上文章进行摘录.总结和测试记录 在使用指令的时候,如果想要使用指令中的子元素,那么你就要用transclusion. 指令的DDO ...
- AngularJS +HTML Demo
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...
- [AngularJS] Transclude -- using what existing in DOM to replace the template elements in directive
var app = angular.module("phoneApp", []); app.controller("AppCtrl", function($sc ...
- AngularJS transclude 理解及例子
一.概念理解 transclude可以在指令中让使用者自定义模板,也就是说,指令中模板的一部分,让指令的使用者动态指定:与指定中的Scope属性值为{}时候的作用类似,scope属性让指令使用者动态制 ...
- AngularJS入门Demo
1 :表达式 <html> <head> <title>入门小Demo-1</title> <script src="angular.m ...
- AngularJs Test demo &front end MVVM implementation conjecture and argue.
<!DOCTYPE html> <html> <head> <title></title> <meta charset="u ...
- angularjs ngRoute demo
<!doctype html> <html lang="en" ng-app="AMail"> <head> <met ...
- angularjs $watch demo
<!doctype html> <html lang="en" ng-app> <head> <meta charset="UT ...
随机推荐
- 本人在安装ADT Bundle for windows的各种问题总结
本人在安装ADT Bundle for windows的各种问题总结 1.解决国内访问Google服务器的困难: 1.启动 Android SDK Manager : 2.打开主界面,依次选择「Too ...
- Taxes
Taxes can be one of the largest cash outflows that a firm experiences.The size of the tax bill(税单) i ...
- TCL随记(1)
string 函数: string compare [-nocase] [-length int] str1 str2 把字符串str1和str2进行比较,返回值为-1/0/1,分别对应str1小于/ ...
- c++ ip地址相关
#include <stdio.h> #include <string.h> #include <arpa/inet.h> #include <sys/typ ...
- UVALive - 6955 Finding Lines 随机算法
题目链接: http://acm.hust.edu.cn/vjudge/contest/126968#problem/F 题意 给你n个点,问是否有>=p/100*n个点共线(p>=20& ...
- 【转载】oracle 分区表详解
一.分区表的概述: Oracle的表分区功能通过改善可管理性.性能和可用性,从而为各式应用程序带来了极大的好处.通常,分区可以使某些查询以及维护操作的性能大大提高.此外,分区还可以极大简化常见 ...
- 【BZOJ】【1912】【APIO2010】patrol巡逻
树形DP 说是树形DP,其实就是求树的最长链嘛…… K=1的时候明显是将树的最长链的两端连起来最优. 但是K=2的时候怎么搞? 考虑第一次找完树的最长链以后的影响:第一次找过的边如果第二次再走,对答案 ...
- 封装dll遇到的奇葩错误:error LNK2005: _DllMain@12 已经在 DLLMain.obj 中定义
在定义一个dll工程的时候,一添加MFC的头文件就会报出这个 错误:error LNK2005: _DllMain@12 已经在 DLLMain.obj 中定义 既蛋疼又蛋疼!! 然后逛论坛,查资料 ...
- Unity上使用Linq To XML
using UnityEngine; using System.Collections; using System.Linq; using System.Xml.Linq; using System; ...
- (转)Learning to Rank for IR的评价指标—MAP,NDCG,MRR
转自:http://www.cnblogs.com/eyeszjwang/articles/2368087.html MAP(Mean Average Precision):单个主题的平均准确率是每篇 ...