为什么ng-repeat矫正不起作用?

费多·帕图金斯基(Fedor Patutinskiy)

我正在学习angular的基础知识,我不能理解,为什么ng-repeat不起作用。

档案app.js

(function(){
var app = angular.module('store', [ ]);

app.controller('StoreController', function(){
this.product=gems;

});

var gems = [
    {
        name: "Dodecahedron",
        price: 2.95,
        description: '...',
        canPurchase: true,
    },  
    {
        name: "Pentagonal Gem",
        price: 5.95,
        description: '...',
        canPurchase: false,
    }
];
})();

index.html

<!DOCTYPE html> 
<html ng-app="store">
    <head>
        <link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
        <script type="text/javascript" src="angular.min.js"></script>
        <script type="text/javascript" src="app.js"></script>
    </head>
    <body ng-controller="StoreController as store">
        <div ng-repeat="product in store.products">
            <h1>{{store.product.name}}</h1>
            <h2> ${{store.product.price}}</h2>
            <p>{{store.product.description}}</p>
            <button ng-show="store.product.canPurchase"> Add to Cart </button>
        </div>
    </body>
</html>

还要补充一点,如果我尝试不以任何方式查看它(例如store.product [0] .description),它会正常工作。

Oleksandr T.
(function(){
  var app = angular.module('store', []);


  app.controller('StoreController', function ($scope) {
     $scope.products = [{
          name: "Dodecahedron",
          price: 2.95,
          description: '...',
          canPurchase: true,
       }, {
          name: "Pentagonal Gem",
          price: 5.95,
          description: '...',
          canPurchase: false,
      }];
  });

})();

<body ng-controller="StoreController as store">
    <h1>APP</h1>

    <div ng-repeat="product in products">
        <h1>{{product.name}}</h1>
        <h2> ${{product.price}}</h2>
        <p>{{product.description}}</p>

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

http://jsbin.com/dejita/1/

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

嵌套ng-repeat不起作用

来自分类Dev

角度ng-repeat不起作用

来自分类Dev

AngularJS ng-repeat不起作用

来自分类Dev

ng样式在嵌套ng-repeat内部不起作用

来自分类Dev

为什么AngularJS ng-view在本地不起作用?

来自分类Dev

为什么嵌套的ng-grid高度不起作用?

来自分类Dev

ng-if在嵌套ng-repeat下不起作用

来自分类Dev

为什么此表达式在ng-repeat内部不起作用?

来自分类Dev

为什么ng-click不起作用?

来自分类Dev

角度:ng-repeat不起作用

来自分类Dev

为什么ng-disabled不起作用?

来自分类Dev

为什么ng-class不起作用?

来自分类Dev

为什么ng-repeat在使用angular的指令中不起作用?

来自分类Dev

在angularjs的ng-repeat之外,作用域不起作用

来自分类Dev

为什么ng-if不起作用?

来自分类Dev

嵌套的ng-repeat不起作用

来自分类Dev

AngularJS ng-repeat不起作用

来自分类Dev

为什么我的ng-show不起作用?

来自分类Dev

AngularJS:为什么这个委派的ng-repeat在转换内不起作用?

来自分类Dev

为什么ng-repeat矫正不起作用?

来自分类Dev

角度:ng-repeat不起作用

来自分类Dev

在JSON对象上使用ng-repeat不起作用-为什么?

来自分类Dev

AngularJS ng-repeat不起作用

来自分类Dev

为什么我的ng-view动画不起作用?

来自分类Dev

为什么ng-class不起作用?

来自分类Dev

不确定ng-click为什么不起作用

来自分类Dev

为什么我的表单在ng-repeat内不起作用?

来自分类Dev

为什么ng-click在示例中不起作用

来自分类Dev

为什么data-ng-file-select不起作用?