2014-10-08 72 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

相關問題