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的更多相关文章

  1. angularjs可交互的directive

    angularjs可交互的directive http://jsfiddle.net/revolunet/s4gm6/ directive开发上手练手,以注释的方式说明 html <body n ...

  2. AngularJs学习笔记--Understanding the Model Component

    原版地址:http://docs.angularjs.org/guide/dev_guide.mvc.understanding_model 在angular文档讨论的上下文中,术语“model”可以 ...

  3. AngularJs学习笔记--Understanding the Controller Component

    原版地址:http://docs.angularjs.org/guide/dev_guide.mvc.understanding_model 在angular中,controller是一个javasc ...

  4. AngularJS系统学习之Directive(指令)

    本文转自https://www.w3ctech.com/topic/1612 原文作者: Nicolas Bevacqua 原文:AngularJS’ Internals In Depth, Part ...

  5. AngularJS入门心得1——directive和controller如何通信

    粗略地翻了一遍<JavaScript DOM编程艺术>,就以为可以接过AngularJS的一招半式,一个星期过去了,我发现自己还是Too Young,Too Simple!(刚打照面的时候 ...

  6. angularjs directive and component 指令与组件 ( 1.5.0 以后 )

    之前写过一篇了 http://www.cnblogs.com/keatkeat/p/3903673.html 但某些部分写的不太清楚,甚至有点错误,所以今天特地在这里再来谈谈. 这篇主要是说指令的隔离 ...

  7. AngularJs(Part 11)--自定义Directive

    先对自定义Directive有一个大体的映像 myModule.directive('myDirective',function(injectables){ var directiveDefiniti ...

  8. [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 ...

  9. angularjs学习笔记三——directive

    AngularJS 通过被称为 指令 的新属性来扩展 HTML. 正如你所看到的,AngularJS 指令是以 ng 作为前缀的 HTML 属性. HTML5 允许扩展的(自制的)属性,以 data- ...

随机推荐

  1. 利用Merge Into 更新表,集合数据到数据库中

    使用Merge INTO 将表数据更新到数据库中 创建User-Defined Table Types   创建要更新的UserDetails表 创建更新存储过程 程序调用存储过程 查看结果

  2. 【转】java提高篇(十)-----详解匿名内部类

    原文网址:http://www.cnblogs.com/chenssy/p/3390871.html 在java提高篇-----详解内部类中对匿名内部类做了一个简单的介绍,但是内部类还存在很多其他细节 ...

  3. 随心所欲的DateTime显示格式

    任何项目,难免会碰到DateTime的显示问题,.net框架虽提供丰富多样的显示方法,但我很少使用,因老忘记细节,每次都要纠结到底月份在前还是年份在前:日期分隔符到底是“/”,还是“\”,还是“-”等 ...

  4. linux中的设备名称和设备号

    看赵炯博士的<linux 0.11 源代码注释>已经两三周了,从今天起开始将一些个人总结和感悟分小标题写出来,聊作记忆以供后来查看.在linux0.11源码的 /linux/boot/bo ...

  5. Ramdisk文件系统的制作与调试运行

    开发环境:Fedora 9交叉编译工具链:arm-linux-gcc 4.3.2 with EABI嵌入式Linux内核版本:2.6.29.4-FriendlyARM.昨天写贴子的时候具体记不清了,今 ...

  6. java jvm学习笔记二(类装载器的体系结构)

    欢迎装载请说明出处:http://blog.csdn.net/yfqnihao                 在了解java虚拟机的类装载器之前,有一个概念我们是必须先知道的,就是java的沙箱,什 ...

  7. opencv 在工业中的应用:圆孔定位

    在工业中产品或者夹具上经常有圆形孔,我们可以利用这些孔来对产品或者夹具进行定位.我用OPENCV写了个DEMO 程序,介绍如下: (1)首先点击打开图像按钮打开一幅图像 (2)进行一些参数设置 (3) ...

  8. Python的数据类型的一些知识

    int 类型表示(正负)整数,str 类型表示字符串(Unicode字符序列): 所表示的整数大小只受限于机器内存,而非固定的字节数. 字符串可以用双引号或是单引号封装,需要成对的出现. 传统上,py ...

  9. bzoj 3551 [ONTAK2010]Peaks加强版(kruskal,主席树,dfs序)

    Description [题目描述]同3545 Input 第一行三个数N,M,Q. 第二行N个数,第i个数为h_i 接下来M行,每行3个数a b c,表示从a到b有一条困难值为c的双向路径. 接下来 ...

  10. codeforces 617B Chocolate

    题意: 在给定01串中,问能分割成多少个子串?每个子串只有一个1. dp #include<iostream> #include<string> #include<alg ...