2014-10-08 66 views
-1

我很难找出问题所在。AngularJS:参数'Controller as short'不是一个函数,没有定义

为什么这个代码(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> 

产生一个错误:'Error:参数 'TabController作为标签' 不是一个函数,在得到未定义错误(本地)“

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' 
    } 
    ]; 
})(); 

非常感谢您提前!

+1

查看您的版本中功能的可用性。 – PSL 2014-10-09 00:20:02

回答

4

您的问题是由于您引用了Angular 1.0.6而引起的。 “Controller as”语法在Angular pre 1.2.0中不可用。如果你将1.0.6更改为1.2.0,它应该可以正常工作。

+0

谢谢你,更新也使这个http://stackoverflow.com/questions/18481863/failed-to-instantiate-module-injectorunpr-unknown-provider-routeprovider必要 – Boern 2014-10-09 08:18:15

+0

甜心男人,很高兴你有事情制定出来! – wjohnsto 2014-10-09 17:29:04

相关问题