[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 函数返回本身的第一个参数.这个函数一般用于函数风格. ----------以上是官网对该接口的说明,只能说这个文档写得也太二,让人完全看不懂.要理解它的用途,可直接看 ...
随机推荐
- spring-data-mongodb一个系统xml文件里面配置两个数据源
spring-data-mongodb一个系统xml文件里面配置两个数据源 参考文档如下: http://www.iteye.com/problems/92789 http://stackoverfl ...
- TextView drawablePadding没有效果
1.当TextView 设置宽度设置为match_parent的时候 TextView drawablePadding没有效果 ,字设置了center位置,但是和左边的图片离开很远 2.当TextVi ...
- WebStorm修改默认快捷键
打开 "File" -> "Setting" -> "keymap",即可修改.
- VM下Linux网卡丢失(pcnet32 device eth0 does not seem to be ...)解决方案
系统启动日志:Bringing up interface eth0: pcnet32 device eth0 does not seepresent, delaying initialization. ...
- iOS中使用图片作为颜色的背景图
Objective-C: [UIColor colorWithPatternImage:[UIImage imageNamed:@"jpg"]]; Swift: UIColor(p ...
- JavaScript 超类与子类 继承
//超类和子类 继承的实现 function R(w, h) { var date = new Date(); this.width = w; this.height = h; this.create ...
- 你好,C++(24)好大一个箱子!5.1.1 函数的声明和定义
第5章 用函数封装程序功能 在完成功能强大的工资程序V1.0之后,我们信心倍增,开始向C++世界的更深远处探索. 现在,我们可以用各种数据类型定义变量来表达问题中所涉及的各种数据:用操作符连接这些变量 ...
- SQL 把数据从一张表更新到另一张表
代码写多了,有些使用过的方法和技巧会一时半会想不起来,平日记录下来,方便自己和有需要的人日后查阅. UPDATE tb1 SET tb1.fieldOne = tb2.fieldOne /* 将原始表 ...
- 无缝滚动js (手写通俗易懂)
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- discuz 万能SQL查询调用语句写法
首先在最底层source\class\table写入底层安全调用文件例如:table_common_friendlink.php 代码: <?php /** * [Discuz!] (C)200 ...