2014-05-06 52 views
0

我有一个像嵌套项目列表项目的控制。 比方说:AngularJS指令 - 从templateUrl方法访问父属性

列表

  • 项目1
  • 项指令我可以设置模板URL像这里面的第2项
  • 项n,

templateUrl: (tElement, tAttrs) -> 
    tAttrs.template or '/item-template.html' 

它工作在f但我想存储模板URL作为父母的属性,以避免设置每个项目的模板。显然,每个项目的模板都是一样的。

范围尚未设置在此阶段。所以我觉得最简单的方法来实现:

templateUrl: (tElement, tAttrs) -> 
    tElement.parent().attr('template') or '/item-template.html' 

,但我不知道这是最好的办法......

所以我的问题是 - 什么是实现这一目标的最佳途径?

谢谢!

+0

看看[在指令指南中创建通信的指令](https://docs.angularjs.org/guide/directive)。你可以做类似的事情,但你可以在(子)项指令中使require成为可选项 – JoseM

回答

0

我与includes in jade.

// index.jade 
doctype html 
html 
    include includes/head 
body 
    h1 My Site 
    p Welcome to my super lame site. 
    include includes/foot 

我喜欢保持markupy东西出来的代码,你在做什么感觉markupy解决这个。