【问题标题】:ng-repeat is not populating <info-window>ng-repeat 未填充 <info-window>
【发布时间】:2014-10-25 12:57:15
【问题描述】:

我在我的应用程序中使用了angularjs-google-maps 指令,到目前为止它一直运行良好。

我试图在&lt;info-window&gt; 中显示Items 和Shop。但是,ng-repeat 没有被填写,我不知道为什么。

<map>

    <div ng-repeat="shop in shops">

        <marker id="{{shop.shop_name}}" 
                position="{{shop.position}}" 
                title="{{shop.shop_name}}"
                on-click="showInfoWindow(event, shop.id)"></marker>

        <info-window id="{{shop.id}}" visible-on-marker="{{$index}}">
            <div style="width: 500px; height: 300px;">
                {{ shop.shop_name }} <br />

                {{ shop.items[0].name }}

                <!-- This line is not working -->
                <div ng-repeat="item in shop.items">{{$index}}|{{item.name}}</div>

                <div class="clear"></div>
            </div>
        </info-window>

    </div>

</map>

为什么ng-repeat 没有填充&lt;info-window&gt; 中的数据?

【问题讨论】:

  • {{ shop.items[0].name }} 显示什么吗?它是没有出现在屏幕上还是没有出现在呈现的 html 中?

标签: javascript angularjs google-maps google-maps-api-3 angularjs-directive


【解决方案1】:

你的代码没有明显的问题,因为给定

$scope.shops = [{
  id: 1,
  name: 'name1',
  items: [1,2]
},{
  id: 2,
  name: 'name2',
  items:[3,4,5]
}];

然后是 HTML 模板

<div ng-controller="" class="ng-scope">
  <map center="" zoom="">
    <info-window id="1" position="">
      <div ng-non-bindable="">
        <div ng-repeat="shop in shops">
          <div>
            shop id:{{ shop.id }} name:{{shop.name}}
          </div>
          <div ng-repeat="item in shop.items">
            item:{{ item }}
          </div>
        </div>
      </div>
    </info-window>
  </map>
</div>

给你

相关plunker在这里http://plnkr.co/edit/kJvhCX

【讨论】:

  • 这确实在info-window 外部工作,但在内部却不行
  • 编辑了答案。您需要将内容包装在 &lt;div ng-non-bindable=""&gt;&lt;/div&gt; 周围
  • 你的 plunker 不再工作了。我没有涉及的另一个问题是,如果存在 ng-non-bindable 包装器,绑定应该如何工作?
  • 似乎 ngMap 项目发生了一些变化,ng-non-bindable 之前是解决方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-11
  • 2015-03-19
  • 1970-01-01
相关资源
最近更新 更多