[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- ...
随机推荐
- Datalist增删改查——联系人管理
关于Datalist,其实和Repeater差不多,都是存放数据的控件,相比较下,Datalist和Repeater虽然都是用的模板,但是Datalist比之多了Edit模板,也就是编辑栏的模板,事件 ...
- 自定义一个compass可编译的目录结构
在学习compass的过程中, 根绝文档说明,如果使用compass create myObject命令会创建一个标准的Compass项目目录结构,如下图: 此时如果使用compass compile ...
- 在线API,桌面版,jquery,css,Android中文开发文档,JScript,SQL掌用实例
学习帮助文档大全 jquery,css,Android中文开发文档,JScript,SQL掌用实例 http://api.jq-school.com/
- LeetCode Product of Array Except Self (除自身外序列之积)
题意:给一个序列nums,要求返回一个序列ans,两序列元素个数相同,ans第i个元素就是除了nums[i]之外所有的数相乘之积. 思路:时间O(n),额外空间O(0). 第一次扫一遍,处理nums[ ...
- light开发框架
- Android学习的一些问题
如何让Service常驻后台? 如何让App自启动? 如何让App自动更新? Handler Adapter Bundle Application getXXX()
- android捕获ListView中每个item点击事件
转自:http://www.cnblogs.com/pswzone/archive/2012/03/10/2389275.html package com.wps.android; import ...
- POJ 2486-Apple Tree(树状背包)
题意 n个节点的树,每个节点都有价值,求在树上最多走k步获得的最大价值(从1开始走,节点的价值只能获取一次) 分析: 开始以为是最基础的树形背包,但后来发现,不能只走子树,有可能还回到根节点,dp[i ...
- Petshop学习第三天
ASP.NET缓存 ASP.NET充分利用缓存机制,通过某种方法,将系统需要的数据对象.Web页面存储在内存中,使得Web站点需要这些数据时,不经过繁琐的数据库连接.查询和复杂的逻辑运算,就可以触手可 ...
- HW6.27
import java.util.Scanner; import java.util.Arrays; public class Solution { public static void main(S ...