【发布时间】:2014-12-03 16:55:15
【问题描述】:
我很难找出问题所在。
为什么这段代码(index.html)会运行
<!DOCTYPE html>
<html ng-app="gemStore">
<head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</head>
<body>
<div class="list-group-item" ng-repeat="product in store.products">
<section ng-controller="TabController as tab">
</section>
</div>
</body>
</html>
同时
<!DOCTYPE html>
<html ng-app="gemStore">
<head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</head>
<body>
<section ng-controller="TabController as tab">
</section>
</body>
</html>
产生错误:'错误:参数'TabController as tab'不是函数,在错误(本机)处未定义'
app.js:
(function() {
var app = angular.module('gemStore', []);
app.controller('StoreController', function() {
this.products = gems;
});
app.controller("TabController", function() {
this.tab = 1;
this.isSet = function(checkTab) {
return this.tab === checkTab;
};
this.setTab = function(setTab) {
this.tab = setTab;
};
});
var gems = [
{
data : 'data'
}
];
})();
非常感谢您!
【问题讨论】:
-
查看您的版本中功能的可用性。
标签: javascript angularjs