Angular传递变量以包含文件

时间:2016-03-11 05:47:16

标签: javascript angularjs angularjs-scope

在搜索并尝试了很多东西之后,我似乎无法找到将范围对象传递到包含文件的解决方案。

我试过了

<span ng-init="list_title = clients_list.title;
               list_subtitle = clients_list.subtitle;
               list_array = clients_list.clients" 
      ng-include="'/views/partials/lists/list_with_qty.html'">
</span>

 <span onload="list_title = publishers_list.title;
               list_subtitle = publishers_list.subtitle;
               list_array = publishers_list.clients"
       ng-include="'/views/partials/lists/list_with_qty.html'">
 </span>

<span ng-include-variables="list_title = publishers_list.title;  
                            list_subtitle = publishers_list.subtitle; 
                            list_array = publishers_list.clients" 
      ng-include="'/views/partials/lists/list_with_qty.html'">
</span>

当他们自己在页面上调用时,它们都会通过对象。 但是我试图将这两者包括在一起。

如何通过变量以使结果不相同。

提前致谢。

1 个答案:

答案 0 :(得分:3)

请参考此plunkr http://plnkr.co/edit/M9cIxNfRIWA8gB41rx1Q?p=preview我已制定了具有隔离范围的指令。将模板替换为给定的list.html

angular.module('app', []).directive('listWithQty', function() {
  return{
    scope: {
        listTitle: '=',
        listSubtitle: '=',
        listArray: '='
      },
      templateUrl: 'list.html'
  }