Coursera - 学习Angular - 为什么我的app.js无法加载?

时间:2016-07-07 00:02:08

标签: javascript html angularjs

我已经按照给我的指示输入了HTML代码。 但是当我尝试加载页面时它只给了我:

标签: 菜单 开胃菜 电源 甜点

描述:  image:dish.name,dish.name,dish.label,dish.price |货币,dish.description

我认为它可能是我正在运行的角度版本,但我刚刚下载了最新版本,它仍然无法正常工作。我已经尝试将文件移动到与html文件相同的目录中,同样的问题。然后我尝试将角度和应用程序代码放在html文档本身中,但结果仍然相同。我甚至删除了缓存,认为这将是问题,但仍然有相同的观点。

我知道这是愚蠢的事,但我的大脑已经被炒了,我无法看到森林中的树木。所有的css加载都很好。它只是没有加载的app.js。我将包括main.html,然后是下面的app.js文件,以获取更多提示。我正在尝试进入我学习Grunt的课程部分(因此构建/建立评论。)所以我非常感谢一些帮助。

<!-- MAIN.HTML -->
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Ristorante Con Fusion: Menu</title>
<!-- Bootstrap -->
<!-- build:css styles/main.css -->
<link href="../bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="../bower_components/bootstrap/dist/css/bootstrap-theme.min.css" rel="stylesheet">
<link href="../bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<link href="styles/bootstrap-social.css" rel="stylesheet">
<link href="styles/mystyles.css" rel="stylesheet">
<!-- endbuild -->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>

<body>

<div class="container">
<div class="row row-content" ng-controller="menuController as menuCtrl">
<div class="col-xs-12">

<ul class="nav nav-tabs" role="tablist">
<li role="presentation" ng-class="{active:menuCtrl.isSelected(1)}">
<a ng-click="menuCtrl.select(1)" aria-controls="all menu" role="tab">The Menu</a>
</li>
<li role="presentation" ng-class="{active:menuCtrl.isSelected(2)}">
<a ng-click="menuCtrl.select(2)" aria-controls="appetizers" role="tab">Appetizers</a>
</li>
<li role="presentation" ng-class="{active:menuCtrl.isSelected(3)}">
<a ng-click="menuCtrl.select(3)" aria-controls="mains" role="tab">Mains</a>
</li>
<li role="presentation" ng-class="{active:menuCtrl.isSelected(4)}">
<a ng-click="menuCtrl.select(4)" aria-controls="dessert" role="tab">Desserts</a>
</li>
</ul>
<div class="tab-content">
<ul class="media-list tab-pane fade in active">
<li class="media" ng-repeat="dish in menuCtrl.dishes | filter:menuCtrl.filtText">
<div class="media-left media-middle">
<a href="#">
<img class="media-object img-thumbnail" ng-src="{{dish.image}}" alt="{{ dish.name }}">
</a>
</div>
<div class="media-body">
<h2 class="media-heading">{{ dish.name }} <span class="label label-danger label-xs">{{ dish.label }}</span> <span class="badge">{{ dish.price | currency }}</span></h2>
<p>{{ dish.description }}</p>
</div>
</li> 
</ul>
</div>
</div>
</div>
</div>
<!-- build:js scripts/main.js -->
<script type="text/javascript" src="../bower_components/angular/angular.min.js"></script>
<script type="text/javascript" src="scripts/app.js"></script>
<!-- endbuild -->
</body>

</html>

<!-- SCRIPTS/APP.JS -->
var app = angular.module('confusionApp', [])

.controller('menuController', function(){
this.tab = 1;
this.filtText = '';

var dishes=[
{
name: 'Uthapizza',
image: 'images/uthapizza.png',
category: 'mains',
label: 'Hot',
price:'4.99',
description: 'A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.',
comment: ''
},
{
name: 'Zucchipakoda',
image: 'images/Zucchipakoda.png',
category: 'appetizer',
label: '',
price:'1.99',
description: 'Deep-fried with mildly spiced Chickpea flour batter accompanied with a tamarind sauce.',
comment: ''
},
{
name: 'Vadonut',
image: 'images/vadonut.png',
category: 'appetizer',
label: 'New',
price:'1.99',
description: 'A quintessential experience, is it a vada or is it a donut.',
comment: ''
},
{
name: 'ElaiCheese Cake',
image: 'images/elaicheesecake.png',
category: 'dessert',
label: '',
price:'2.99',
description: 'A delectable, semi-sweet New York Style Cheese Cake with Graham cracker crust spiced with Indian cardamoms',
comment: ''
}
];
this.dishes = dishes;

this.select = function(setTab){
this.tab = setTab;

if(setTab === 2)
this.filtText = "appetizer";
else if(setTab === 3)
this.filtText = "mains";
else if(setTab === 4)
this.filtText = "dessert";
else
this.filtText = "";
}

this.isSelected = function(checkTab) {
return (this.tab === checkTab);
}
});

2 个答案:

答案 0 :(得分:0)

您遗漏了ng-app,用于初始化页面中的角度

更改

<html lang="en">

<html lang="en" ng-app="confusionApp">

答案 1 :(得分:0)

这正是已经说过的。我错过了ng-app变量。当我将它从一个文件传输到另一个文件时,我肯定已经丢失了。再次感谢。