2016-01-31 63 views
2

我正在嘗試學習Angular JS。我寫了一小段代碼,但由於某些原因,我無法通過HTML來識別Angular.JS。爲什麼我的HTML不能識別我的Angular JS

我的index.html文件:

<!DOCTYPE HTML> 
<html ng-app="store"> 
    <head> 
    <link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css"/> 
    </head> 
    <body> 
     <div ng-controller = "storeController as store"> 
      <h1>{{store.product.name}}</h1> 
     </div> 
     <script type = "text/javascript" src = "angular-1.2.29/angular.min.js"></script> 
     <script type = "text/javascript" src= "app.js"></script> 
    </body> 
</html> 

我app.JS文件:

(function() { 
var app = angular.module('store', [ ]); 
app.controller('StoreController', function() { 
    this.product = item; 
}); 
var item = { 
    name: 'stuff', 
    price: 2.44, 
    description: 'lame', 
} 
})(); 

我的輸出爲{{store.product.name}},而不是 '東西' 是我期待着。

回答

3

我會建議嘗試和匹配的情況下,一個錯字:

<div ng-controller = "StoreController as store"> 

資本S.

+1

這做到了!, 謝謝。我已經檢查了這個東西100次,我不能相信我錯過了。 –

+0

哈哈這一直髮生在我身上;) – Idos

1

修復該行具有相同名稱

<div ng-controller = "storeController as store"> 

<div ng-controller="StoreController"> 

'Controller as syntax' is a good thing,但在你的情況下,你命名的應用程序。

而做出的',而不是 'S' 作爲@Idos注意到

相關問題