[英]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.