大家好,我无法理解为什么我的简单代码无法正常工作
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>
<div ng-controller="StoreController as store">
<h1> {{store.prodotto.name}} </h1>
<h2> {{store.prodott.surname}} </h2>
<p> {{store.prodotto.town}} </p>
</div>
</body>
</html>
app.js:
(function(){
var app = angular.module('store', []);
app.controller('StoreController', function(){
this.product = prodotto;
});
var prodotto = {
name = 'David',
surname = 'Gilmour',
town = 'Cambridge',
}
})();
这两个文件与&#34; angular.min.js&#34;在同一文件夹中。和&#34; bootstrap.min.js&#34;
谁能帮助我吗? 非常感谢。答案 0 :(得分:4)
你的javascript中有一些语法错误;
而不是
var prodotto = {
name = 'David',
surname = 'Gilmour',
town = 'Cambridge',
}
使用
var prodotto = {
name : 'David',
surname : 'Gilmour',
town : 'Cambridge'
};
另外,似乎你接受了错误的变量名称
而不是
<div ng-controller="StoreController as store">
<h1> {{store.prodotto.name}} </h1>
<h2> {{store.prodott.surname}} </h2>
<p> {{store.prodotto.town}} </p>
</div>
使用
<div ng-controller="StoreController as store">
<h1> {{store.product.name}} </h1>
<h2> {{store.product.surname}} </h2>
<p> {{store.product.town}} </p>
</div>