angular-directive(组件化)
来源:互联网 发布:织梦cms免费模板 编辑:程序博客网 时间:2024/05/16 05:00
base.js
var myApp = angular.module('helloworld', []);myApp.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 toggle() { scope.showMe = !scope.showMe; } } }});
html
这里的代码需要ng-app的包裹才会生效
大家自己加
<expander class='expander' expander-title='title'> {{text}} </expander>
这里的{{text}}为何会插入到'<div class="body" ng-show="showMe" ng-transclude></div>'
这里面 我很好奇啊搜了一下 哈哈
找到了这句话`
directive包含的内容会放在ng-transclude标示的元素中,transclude要配合ng-transclude使用 所以啦这里的 {{text}}最终会在
'<div class="body" ng-show="showMe" ng-transclude></div>'
这里面包裹着这样我这个例子 我就没有疑问了
1 0
- angular-directive(组件化)
- angular directive
- angular directive
- 详说Angular之指令(directive)
- angular.js基础(1)--指令directive
- angular学习(十二)—— Directive
- Angular 指令(Directive)属性型指令
- angular directive中scope:{}
- angular directive详解
- angular scope of directive
- Angular directive 递归渲染
- Angular directive bug
- angular directive的使用
- angular directive 总结
- angular directive简介
- angular directive(指令)
- angular directive 不生效
- angular directive 入门
- 我们的敏捷之路——技术转型篇
- Lecture 1 Analysis of Algorithms
- 在iOS微信浏览器中自动播放HTML5 audio(音乐)的2种正确方式
- 字典序问题(暴力)
- linux下如何使用vnstat查看服务器带宽流量统计
- angular-directive(组件化)
- 正则表达式学习教程
- 最大公约数
- 联想G475 光盘安装win10
- css的position属性取值
- 读书笔记:《HTML5开发手册》-- 现存元素的变化
- Yeoman-generator 流行的生成器
- 17.4.1 有感
- 有你真好,我的程序员老公