[AngularJS] 'require' prop in Directive or Component
When use 'require', recommend to add some error check, for example:
class ChildCtrl {
constructor(){
// Get prop from parent ctrl
if(this.parentCtrl){
this.childProp = this.parentCtrl.prop;
}
}
}
app.directive('someDirective', () => {
return {
require: {
'parentCtrl': '?^^'
},
controller: ChildCtrl,
controllerAs: 'vm',
bindToController: true,
scope: {},
template: require('./child.tpl.html')
}
})
We add a if() to check whether this is parent controller, if it is then we continue do something, if not, just ignore. This can prevent if there is no parent controller, we won't get undefined error
[AngularJS] 'require' prop in Directive or Component的更多相关文章
- angularjs可交互的directive
angularjs可交互的directive http://jsfiddle.net/revolunet/s4gm6/ directive开发上手练手,以注释的方式说明 html <body n ...
- AngularJs学习笔记--Understanding the Model Component
原版地址:http://docs.angularjs.org/guide/dev_guide.mvc.understanding_model 在angular文档讨论的上下文中,术语“model”可以 ...
- AngularJs学习笔记--Understanding the Controller Component
原版地址:http://docs.angularjs.org/guide/dev_guide.mvc.understanding_model 在angular中,controller是一个javasc ...
- AngularJS系统学习之Directive(指令)
本文转自https://www.w3ctech.com/topic/1612 原文作者: Nicolas Bevacqua 原文:AngularJS’ Internals In Depth, Part ...
- AngularJS入门心得1——directive和controller如何通信
粗略地翻了一遍<JavaScript DOM编程艺术>,就以为可以接过AngularJS的一招半式,一个星期过去了,我发现自己还是Too Young,Too Simple!(刚打照面的时候 ...
- angularjs directive and component 指令与组件 ( 1.5.0 以后 )
之前写过一篇了 http://www.cnblogs.com/keatkeat/p/3903673.html 但某些部分写的不太清楚,甚至有点错误,所以今天特地在这里再来谈谈. 这篇主要是说指令的隔离 ...
- AngularJs(Part 11)--自定义Directive
先对自定义Directive有一个大体的映像 myModule.directive('myDirective',function(injectables){ var directiveDefiniti ...
- [AngularJS + Unit Testing] Testing Directive's controller with bindToController, controllerAs and isolate scope
<div> <h2>{{vm.userInfo.number}} - {{vm.userInfo.name}}</h2> </div> 'use str ...
- angularjs学习笔记三——directive
AngularJS 通过被称为 指令 的新属性来扩展 HTML. 正如你所看到的,AngularJS 指令是以 ng 作为前缀的 HTML 属性. HTML5 允许扩展的(自制的)属性,以 data- ...
随机推荐
- android LayoutInflater和inflate()方法的用法(转载)
原文出处:http://www.cnblogs.com/top5/archive/2012/05/04/2482328.html 在实际开发中LayoutInflater这个类还是非常有用的,它的作用 ...
- NopCommerce架构分析之一----依赖类生成容器
NopCommerce为了实现松耦合的框架设计目的,使用了IOC框架:Autofac.据有人测试,Autofac是性能好的IOC工具. 1.在IOC中,组件首先需要在IOC中注册,有通过配置文件注册的 ...
- poj2686-Traveling by Stagecoach(状压dp)
题意: n张马票,m个城市,马票上有马数(决定速度),一张只能用一次,给出地图,求从城市a到b的最短时间. 分析:n值很小状态压缩 #include <map> #include < ...
- POJ3281 Dining 最大流
题意:有f种菜,d种饮品,每个牛有喜欢的一些菜和饮品,每种菜只能被选一次,饮品一样,问最多能使多少头牛享受自己喜欢的饮品和菜 分析:建边的时候,把牛拆成两个点,出和入 1,源点向每种菜流量为1 2,每 ...
- [BILL WEI]SQL 存储过程学习
--查看数据库exec sp_databases ;--查看表exec sp_tables ;--查看列exec sp_columns WMS_ASN;--查看索引exec sp_helpindex ...
- delphi获取mdb密码
function GetPasswordFromAccess(AFileName: string): string;var myms: TMemoryStream; b: array of Byt ...
- SQLBulkCopy使用
SQLBulkCopy,用于数据库之间大批量的数据传递.通常用于新,旧数据库之间数据的更新.即使表结构完全不同,也可以通过字段间的对应关系,顺利的将数据导过来. 首先,SQLBulkCopy需要2个连 ...
- Colors
.custom_a1, .custom_a2, .custom_a3, .custom_a4{ width:800px; height:100px; line-height:100px; color: ...
- [原]我的CentOS设置
[Date]2013-10-06 [Keywords]Linux.CentOS.Fedora [Environment]CentOS 6.3 Final . Wiz [Content]: 1.安装Fl ...
- Android 依赖注入 ButterKnife 基本使用
ButterKnife 是一个快速 Android View 注入框架,开发者是Jake Wharton,简单的来说,ButterKnife 是用注解的方式替代findViewById和setXXXL ...