gpt4 book ai didi

javascript - 为什么我的 jsangular 没有在我的范围内循环?

转载 作者:行者123 更新时间:2023-12-03 09:30:18 25 4
gpt4 key购买 nike

所以我正在学习 JSAngular 中的指令和 Controller 。目前我只是想让开胃菜在菜单上循环,但似乎无法让输出响应。我在这里缺少什么?提前致谢。

MainController.js:

app.controller('MainController', ['$scope', function($scope) {
$scope.today = new Date();

$scope.appetizers = [
{
name: 'Caprese',
description: 'Mozzarella, tomatoes, basil, balsmaic glaze.',
price: 4.95
},
{
name: 'Bruschetta',
description: 'Grilled bread garlic, tomatoes, olive oil.',
price: 4.95
},
{
name: 'Mozzarella Sticks',
description: 'Served with marinara sauce.',
price: 3.95
}
];

$scope.mains = [
{
name: 'Roast Beef Au Jus',
description: 'Delicious Amazing Sauce',
price: 15.99
},
{
name: 'Prime Rib',
description: 'Just like Jacoby/s',
price: 18.95
},
{
name: 'BBQ Ribs',
description: 'Better than Krupa/s',
price: 15.99
}
]

$scope.extras = [
{
name: 'Cole slaw',
},
{
name: 'Creamed Spinach',
},
{
name: 'Boston Baked Beans',
}
]

}]);
<!doctype html>
<html>
<head>
<link href="https://s3.amazonaws.com/codecademy-content/projects/bootstrap.min.css" rel="stylesheet" />
<link href='https://fonts.googleapis.com/css?family=Playfair+Display:400,400italic,700italic|Oswald' rel='stylesheet' type='text/css'>
<link href="css/main.css" rel="stylesheet" />
<script src="js/vendor/angular.min.js"></script>
</head>
<body ng-app='PizzaPlanetApp'>
<div class="header">
<h1><span>Pizza</span><span>Planet</span></h1>
</div>

<div class="main" ng-controller="MainController">
<div class="container">
<h1>Specials for {{ today | date }}</h1>
<h2>Appetizers</h2>
<div class="appetizers row" ng-repeat="appetizer in appetizers">
<div class="item col-md-9">
<h3 class="name"> {{ appetizer.name }} </h3>
<p class="description"> {{ appetizer.description }} </p>
</div>
<div class="price col-md-3">
<p class="price"> {{ appetizers.price | currency }} </p>
</div>
</div>

</div>
</div>

<div class="footer">
<pizza-footer></pizza-footer>
</div>

<!-- Modules -->
<script src="js/app.js"></script>

<!-- Controllers -->
<script src="js/controllers/MainController.js"></script>
</body>
</html>

最佳答案

您需要首先引用您的PizzaPlanetApp应用程序模块。在创建 Controller 之前添加以下代码行。

var app = angular.module("PizzaPlanetApp", []);

这指的是您要为其创建 Controller 的应用程序,并包含您的应用程序所依赖的模块列表。

在您的情况下,列表为空。

jsfiddle

关于javascript - 为什么我的 jsangular 没有在我的范围内循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31530632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com