繁体   English   中英

Angular gemStore不输出任何内容

[英]Angular gemStore doesn't output anything

我目前正在尝试angularJS看看它是如何工作的。 我遵循了关于egghead.io的教程,这非常好。

摆弄了这个小提琴,但令我烦恼的是我找不到问题/错误。
没有显示/输出

app.js

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

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


    var gems = [
        {
            name: "Soap",
            price: 25,
            quantity: 10,
            canPurchase: false
        }, 
        {
            name: "Bag",
            price: 100,
            quantity: 15,
            canPurchase: false
        }
    ];

});


指数

<body ng-controller="StoreController as store">
<div ng-repeat="product in store.products">
    <h1>{{product.name}}</h1>
    <h2>${{product.price}}</h2>
    <button ng-show="product.canPurchase">Add to cart</button>
</div>

这是小提琴: https : //jsfiddle.net/Vwsej/618/ (已更新)希望您能指出正确的方向。

预先,谢谢。

您忘记了在页面中包含角度。 只需添加:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>

到您的HTML页面。 请注意,jsfiddle在“框架和扩展”下的左上方有一个按钮,可让您快速添加诸如angular的库。

您还忘记了致电IIFE:

(function() {
    //Your JS...
})(); //<--- you forgot the ()

我分叉了你的小提琴,并修复了这些问题 ,效果很好。

您忘记了调用自调用函数:JS Fiddle: https ://jsfiddle.net/Vwsej/620/

这就是自调用结构的方式:

(function(){
    // your js code to execute
})();//forgot to call

暂无
暂无

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

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