简体   繁体   English

angularJS将变量传递给ui.bootstrap模板

[英]angularJS pass variable to ui.bootstrap template

In my view i have such code: 在我看来,我有这样的代码:

<script id="template/accordion/accordion.html" type="text/ng-template">
  <div class="panel-group" data-ng-transclude></div>
</script>
<script id="template/accordion/accordion-group.html" type="text/ng-template">
  <div class="panel panel-default">
    <div class="panel-heading custom">             
      <h4 class="panel-title custom">
        <a href accordion-transclude="heading" data-ng-click="toggleOpen();"><span>{{heading}}</span></a>
      </h4>
    </div>
    <div class="panel-collapse" collapse="!isOpen">
      <div class="panel-body" data-ng-transclude></div>
    </div>
  </div>
</script>
<script type="text/ng-template" id="nodes_renderer.html">
  <accordion close-others="false">
    <accordion-group>
      <accordion-heading>
        {{node.Title}}
      </accordion-heading>                      
      <div data-ng-bind-html="node.Text"></div>                     
    <ol ui-tree-nodes="" data-ng-model="node.Childs">
      <li data-ng-repeat="node in node.Childs" ui-tree-node data-ng-include="'nodes_renderer.html'">
    </li>
    </ol>
    </accordion-group>                   
  </accordion>
</script>
<div ui-tree="options">
  <ol ui-tree-nodes data-ng-model="articles">
    <li data-ng-repeat="node in articles" ui-tree-node data-ng-include="'nodes_renderer.html'"></li>
  </ol>
</div>

is it real to get node.Options.length, when i try to render header here: 当我尝试在此处渲染标头时,获取node.Options.length是否真实:

<div class="panel-heading">             
      <h4 class="panel-title">
        <a href accordion-transclude="heading" data-ng-click="toggleOpen();" class="no-link"><span>{{heading}}</span></a>
      </h4>
    </div>

and then if my node.Options are higher then 0 i do ng-class... 然后如果我的node.options更高然后0我做ng-class ...

how could i pass variable to non-my directive template? 如何将变量传递给非我的指令模板?

also i must pass there whole node object, so that i could edit it etc... 我也必须传递整个节点对象,以便我可以编辑它等...

Every directive lives within a scope. 每个指令都在一个范围内。 I had a similar case where I wrote a common pager directive that pulls its details from the Controller scope. 我有一个类似的案例,我编写了一个通用的寻呼机指令,该指令将其详细信息从Controller范围中提取。 My templates are externalized, but this does not affect the functionality. 我的模板已外部化,但这不会影响功能。

Directive usage: 指令用法:

<div class="row" ng-controller="TableController">
    <table-pager></table-pager>
</div>

Directive definition: 指令定义:

angular.module.directive('tablePager', function() {
    return {
        restrict: 'E',
        replace: true,
        templateUrl: 'templates/table-pager.html'
    };
})

Controller: 控制器:

angular.module.controller('TableController', function($scope, $log, $location) {
    $scope.query = {};
    $scope.limit = 20;
    $scope.offset = 0;
    $scope.currentPage = 0;
    $scope.total = 0;
    ...
}

Template code of templates/table-pager.html (snippet): templates/table-pager.html模板代码(片段):

<div class="row">
    <div class="col-md-4">{{total}} Entries found</div>

    <div class="col-md-4 col-pager">...</div>
</div>

You can read more about AngularJS custom directives at http://tutorials.jenkov.com/angularjs/custom-directives.html 您可以在http://tutorials.jenkov.com/angularjs/custom-directives.html上了解有关AngularJS自定义指令的更多信息。

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM