[AngularJS] Angular 1.5 $transclude with named slot
In Angular 1.5, there is no link and compile. So use if you transclude, you cannot access the fifth arguement in link function, which is transcludeFn.
But in v1.5, you can access $transclude in controller.
And what you can do for that is check whether the transclude element is passed in or not. For that you also need to use named slot, not default transclude: true.
See example:
class ServiceListController {
constructor($transclude) {
this.$transclude = $transclude;
}
hasTransclude(){
return this.$transclude.isSlotFilled('actions');
}
}
const clmServiceListComponent = {
bindings: {
...
},
transclude: {
'actions': '?clmActions'
},
controller: ServiceListController,
controllerAs: 'vm',
template: require('./service-list.html')
};
export default (ngModule) => {
ngModule.component('clmServiceList', clmServiceListComponent);
}
In the example, we has a directive call 'clmActions', and gave slot name as 'actions'.
So you can use:
this.$transclude.isSlotFilled('actions');
to check whether the transclude element is defined or not.
In HTML:
<clm-service-list>
<clm-actions>
<clm-action ></clm-action>
</clm-actions>
</clm-service-list>
If we gave the clm-actions tag, the hasTransclude() function in controller will return 'true', if you remove clm-actions tag, the function will return false.
[AngularJS] Angular 1.5 $transclude with named slot的更多相关文章
- [UE4]Named Slot
用户创建的UI成为其他UI的子控件的时候,默认情况下是不能拥有子控件的,给UI添加一个Named Slot,这个UI就可以拥有子控件 一.创建一个名为testNameSlot的UI,添加3个Named ...
- [AngularJS] Angular 1.5 multiple transclude
If you know ui-router, multi-transclude should be easy for you also. In previou Angular version < ...
- [Angularjs]angular ng-repeat与js特效加载先后导致的问题
写在前面 最近在项目中遇到这样的一个前端的bug,在ng-repeat中绑定的图片,有一个晃动的特效,在手机端浏览的时候,图片有时候会正常展示,有时就展示不出来.当时猜测是因为angularjs与特效 ...
- [AngularJS] Angular 1.3 ngMessages with ngAnimate
Note: Can use $dirty to check whether user has intracted with the form: https://docs.angularjs.org/a ...
- [AngularJS] Angular 1.3 $submitted for Form in Angular
AngularJS 1.3 add $submitted for form, so you can use $submitted to track whether the submit event ...
- [AngularJS] Angular 1.3 Anuglar hint
Read More: http://www.linkplugapp.com/a/953215 https://docs.google.com/document/d/1XXMvReO8-Awi1EZXA ...
- [AngularJS] Angular 1.3 ng-model-options - getterSetter
getterSetter: boolean value which determines whether or not to treat functions bound to ngModel as ...
- [AngularJS] Angular 1.3: ng-model-options updateOn, debounce
<!DOCTYPE html> <html ng-app="app"> <head lang="en" > <meta ...
- AngularJs angular.identity和angular.noop详解
angular.identity 函数返回本身的第一个参数.这个函数一般用于函数风格. ----------以上是官网对该接口的说明,只能说这个文档写得也太二,让人完全看不懂.要理解它的用途,可直接看 ...
随机推荐
- Javascript 追本溯源
一直以来对Javascript的继承关系都是通过死记硬背下来的,对于一个理科生,喜欢逻辑思维的人来讲,死记硬背特别头痛,且理科生对于能够死记硬背下来的东西也很容易忘记,不知道其他理科生童鞋们是否如此, ...
- memcache如何模糊查询
是新的方法,还是get方法本身就有这个功能? 需要用到递归遍历的方法,将所有的key-value扫描出来.
- SOA
面向服务架构Service-Oriented Architecture 4个特性 1每个服务具有明确的边界 2服务是独立的 3采用标准的契约定义和通信协议 4服务是自解释的
- BestCoder Round 59 (HDOJ 5500) Reorder the Books
Problem Description dxy has a collection of a series of books called “The Stories of SDOI”,There are ...
- WPF自定义Main函数
第一步:在app.xaml.cs里加入以下代码: [STAThread] public static void Main(string[] args) { App app = new App(); a ...
- 武汉科技大学ACM:1001: 华科版C语言程序设计教程(第二版)习题6.7
Problem Description 输出杨辉三角前n行. Input 输入一个数n(n <= 9) Output 输出杨辉三角前n行.(注意行末不能有多余的空格,数字以%3d的格式输出) S ...
- java事件处理4(焦点,键盘
FocusEvent焦点事件 接口 addFocusListener(FocusListener listener) 有两个方法 public void focusGains(FocusEvent e ...
- html5中的一些小知识点(CSS)
1.点击a标签周围区域就可以进入超链接: a标签 的css样式中的 display属性设置为block 就可以了 2.文字左右居中: text-align 属性值为 center 3.文字上下居中: ...
- svn用法
SVN安装与启动服务 1.下载相应匹配版本的TortoiseSVN(客户端)和Subversion(客户端),安装完毕之后. 2.配置相关文件. 选择TortoiseSVN-->create r ...
- Linux_install jdk
Linux安装JDK步骤 1.先从网上下载jdk(jdk-7u1-linux-i586.rpm),下载地址:http://www.oracle.com/technetwork/java/javase/ ...