Javascript 视图中未定义控制器
角度错误:错误:参数“StoreController作为store”不是函数,未定义Javascript 视图中未定义控制器,javascript,angularjs,Javascript,Angularjs,角度错误:错误:参数“StoreController作为store”不是函数,未定义 index.html <!DOCTYPE html> <!-- runs the module when the document loads --> <html ng-app='store'> <head> <link rel='stylesheet' type='text/css' href='http://netdna.boo
index.html
<!DOCTYPE html>
<!-- runs the module when the document loads -->
<html ng-app='store'>
<head>
<link rel='stylesheet' type='text/css' href='http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css'/>
</head>
<body>
<!-- expressions -->
<!-- directive controller name alias -->
<div ng-controller='StoreController as store'>
<h1> {{store.product.name}} </h1>
<h2>${{store.product.price}}</h2>
<p>{{store.product.description}}</p>
</div>
<script type = 'text/javascript' src='https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js'></script>
<script type ='text/javascript' src='app.js'></script>
</body>
</html>
app.js
// wrap the function inside a closure.
(function(){
var app = angular.module('store', []);
app.controller('StoreController', function(){
// will be executed when the store controller is called.
this.product = gem;
});
var gem = {
name: 'Dodecahedron',
price: 2.95,
description: '. . .'
};
})();
index.html
{{store.product.name}
${{store.product.price}
{{store.product.description}}
app.js
//将函数包装在闭包中。
(功能(){
var app=angular.module('store',[]);
app.controller('StoreController',function(){
//将在调用存储控制器时执行。
本产品=宝石;
});
var gem={
名称:“十二面体”,
价格:2.95,,
说明:“…”
};
})();
我是angular的新手,每次加载我的应用程序时,我都会在我的chrome控制台上看到上面发布的错误。我认为一切都是正确的。我不知道为什么没有定义函数StoreController,我没有将控制器正确地传递到我的index.html吗?从代码的外观来看,您正在运行Angular 1.0.1:
<script type = 'text/javascript'
src='https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js'></script>
…而控制器作为propertyName
语法选项直到1.1.5才添加。如果您想使用该语法,请加载AngularJS的更新版本。实际上,即使您不需要该语法,也可以加载一个更新的版本;)
从代码外观来看,您运行的是Angular 1.0.1:
<script type = 'text/javascript'
src='https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js'></script>
…而控制器作为propertyName
语法选项直到1.1.5才添加。如果您想使用该语法,请加载AngularJS的更新版本。实际上,即使您不需要该语法,也可以加载一个更新的版本;)