如何在指令模板中包含模板?

How to include template within a directive template?

如何在 angular 指令的模板中包含 .html 模板?

我目前包含模板的方式成功地将模板的 HTML 拉入指令模板,但模板中的变量未链接到控制器。

这是我目前正在做的事情:

_directive_template.html

<section>
  ...
 <div ng-include="'/templates/_template_to_be_included.html'"></div>
  ...
</section> 

_template_to_be_included.html

 <form>
    <input ng-model="some_value">
    <button type="submit">Update</button>
 </form>

指令

...
function link(scope, element, attrs) {
      scope.some_value  // not correctly linking to some_value within included template 
      }
  return {
    scope: {},
    link: link,
    templateUrl: '/templates/_directive_template.html'
  };
....

当我将 _template_to_be_included.html 的 HTML 直接复制并粘贴到指令模板中时(而不是像上面那样使用 ng-include),一切正常并且 some_value 之间正确链接它在表单中的位置及其在控制器中的位置。

如何正确地将模板包含到指令模板中并将其变量链接到指令中的对应变量?似乎 ng-include 应该有效,因为它将 "fetch and compile" 指定的模板...

Plunkr: 输入一些输入并点击 "update"

我相信我理解了这个问题。我组装了一个 Plunker。

http://plnkr.co/edit/L4ZN5XhOpex6U5MRKsZ4?p=preview

<div>
  <h1>Directive Template</h1>
  <p>This is just some garbage text.</p>

  <h1>ng-include template</h1>
  <div ng-include="'_template_to_be_included.html'"></div>
</div>