2017-07-25 39 views
3

正如標題所示,我試圖自學Angular.js,但我遇到了一個意想不到的令人沮喪的路障......我甚至無法讓變量正確顯示在網頁上!角度變量沒有正確顯示在網頁上

<!DOCTYPE html> 
<html ng-app> 
<head> 
    <title>Lets test this out?</title> 
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> 
</head> 
<body> 

    Write your name in the text box! 
    <input type="text" ng-model="sometext" />  
    <h1>Hello {{ sometext }}</h1> 

</body> 
</html> 

我會非常感謝任何人都可以告訴我,我在做什麼錯了,因爲我一直在打我的頭靠在我的辦公桌上了一小時,用Google搜索這個問題,但我不明白爲什麼它不」工作。

+0

在您的身體標記中添加** ng-app **。例如'' – Rostech

+0

這是在這裏工作https://plnkr.co/edit/K8zEYdUhiun2qAgQU2Hi?p=preview –

回答

3

檢查您的角度參考是否已正確加載。嘗試NG-應用程序添加到您的身體標記

DEMO

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<body ng-app> 
 
    Write your name in the text box! 
 
    <input type="text" ng-model="sometext" /> 
 
    <h1>Hello {{ sometext }}</h1> 
 
</body>

+0

你說得對,我通過幾個在線HTML5的情況下運行它,它工作,它可能是IDE我'使用(Angular IDE 2017)由於某種原因,它甚至不能正確渲染代碼。 –

0

這是工作完美的只是你必須刪除第一個標籤

'

<html ng-app> 
<head> 
    <title>Lets test this out?</title> 
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js</script> 
</head> 
<body> 

    Write your name in the text box! 
    <input type="text" ng-model="sometext" /> 

    <h1>Hello {{ sometext }}</h1> 

</body> 
</html> 

'