它应该显示产品列表,但是会返回空白页。...无论如何,如果我不使用ng-repeat,它就可以正常工作...有人可以找到这段代码有什么问题吗?

的HTML

<div ng-controller="directiveController as directive">
    <div ng-repeat="dir in directive.directives">
        <h1>{{ directive.dir.name }}</h1>
        <span>{{ directive.dir.description }}</span>
        <b>{{ directive.dir.price }}</b>

        <button ng-show="directive.dir.canPurchase">Add to Cart</button>
    </div>
</div>


JS

var app = angular.module('gemStore', []);

app.controller('directiveController' ,function(){
    this.directives = gems;
});

var gems =
  [{
      name: 'Produkt 1',
      price: '20 e',
      description:'Na lageru i mozes se poruciti',
      canPurchase: true,
      soldOut: true
  },
  {
      name: 'Produkt 2',
      price: '30 e',
      description:'Nema ga',
      canPurchase: false,
      soldOut: true
  },
  {
      name: 'Produkt 3',
      price: '35 e',
      description:'Trenutno se ne moze poruciti jer je canPurchase false',
      canPurchase: false,
      soldOut: true
  }
  ];

最佳答案

我认为正确的语法是

<div ng-repeat="dir in directive.directives">
    <h1>{{ dir.name }}</h1>
    <span>{{ dir.description }}</span>
    <b>{{ dir.price }}</b>

    <button ng-show="dir.canPurchase">Add to Cart</button>
    </div>

关于javascript - ng-repeat返回空白页[Angular],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30491224/

10-13 04:33