[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 函数返回本身的第一个参数.这个函数一般用于函数风格. ----------以上是官网对该接口的说明,只能说这个文档写得也太二,让人完全看不懂.要理解它的用途,可直接看 ...
随机推荐
- PHP 执行系统外部命令 system() exec() passthru()
区别: system() 输出并返回最后一行shell结果. exec() 不输出结果,返回最后一行shell结果,所有结果可以保存到一个返回的数组里面. passthru() 只调用命令,把命令的运 ...
- pod update或者pod install很慢
最近使用CocoaPods来添加第三方类库,无论是执行pod install还是pod update都卡在了Analyzing dependencies不动 原因在于当执行以上两个命令的时候会升级Co ...
- 你好,C++(24)好大一个箱子!5.1.1 函数的声明和定义
第5章 用函数封装程序功能 在完成功能强大的工资程序V1.0之后,我们信心倍增,开始向C++世界的更深远处探索. 现在,我们可以用各种数据类型定义变量来表达问题中所涉及的各种数据:用操作符连接这些变量 ...
- 纯css实现三角形
在设计界面的时候,通常需要三角形的图标,一般做法是用图片,其实也可以使用css来实现.如下: 向上的三角形 向右的三角形 向下的三角形 向左的三角形 实现它们的css分别是: .top ...
- 【Ecstore2.0】计划任务/队列/导入导出 的执行问题
[环境]CENTOS6.3 + wdcp(php5.3) [症状]可正常加入队列,但不执行队列 [原因]大部份都是用户权限造成 [原理] Ecstore2.0的导入导出.发送邮件.日常清理备份等任务操 ...
- CentOS下安装vsftpd架设ftp服务器
什么是vsftpd vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序.特点是小巧轻快,安全易用. 首先安装vsftpd这个软件,命令是,yum install vsftpd servi ...
- css图片磨砂化
Css代码: .blur { filter: url(blur.svg#blur); /* FireFox, Chrome, Opera */ -webkit-filter: blur(10px); ...
- C#中HashTable和快速排序的用法
题目主要是写一个程序,分析一个文本文件(英文文章)中各个词出现的频率,并且把频率最高的10个词打印出来. 自从周四拿到题目以后,发现又要用到万恶的数据结构了,不得不说这是我的短板,所有上周20号到 ...
- Linux 在一个命令行上执行多个命令(转载)
对于单个命令执行我想大多数人都是明了的,也就是在一个命令行上执行一条命令.那对于在一行上执行多个命令怎么办呢,其实也很简单,只需在各命令之间加上特殊命令符号,我们常规使用到的有3个特殊命令符号. 1. ...
- python实现发工资脚本
好开心啊,在旁边大神的帮助下,终于实现了发工资的python脚本,之前用shell写的老出错,刚才测试,发80个人工资详情,妥妥的,代码如下: from email.mime.multipart im ...