2016-06-25 101 views
-1

請幫助確定,下面的角度Hello World中出了什麼問題!第一個程序。角度實例化模塊錯誤

<html> 
 
\t <head> 
 
\t \t <script type="text/javascript" language="javascript" src="Scripts/angular.js" /> 
 
\t \t <script type="text/javascript" language="javascript" src="Scripts/angular-resource.js" /> 
 
\t \t <script type="text/javascript" language="javascript" src="Scripts/angular-route.js" /> 
 
\t \t <script type="text/javascript" language="javascript" src="Scripts/angular-cookies.js" /> 
 
\t \t <script type="text/javascript" language="javascript" src="Scripts/angular-sanitize.js" /> 
 
     
 
\t \t <script type="text/javascript" language="javascript"> 
 
\t \t \t function Student($scope){ 
 
\t \t \t \t $scope.Name= 'Akshay'; 
 
\t \t \t \t $scope.City= 'Mumbai'; \t \t \t \t 
 
\t \t \t }; 
 
\t \t \t 
 
\t \t \t var app = angular.module("myApp"); 
 
\t \t \t app.controller("Student", Student) 
 
\t \t </script> 
 
\t </head> 
 
\t <body ng-app="myApp"> 
 
\t \t <form> 
 
\t \t <div id="dvStudent" ng-controller="Student"> 
 
\t \t \t Name: <input type="text" name="txtStudentName" id="txtStudentName" ng-model="Name" /> 
 
\t \t \t City: <input type="text" name="txtStudentCity" id="txtStudentCity" ng-model="City" /> 
 
\t \t \t <input type="button" name="btnSave" id="btnStudentSave" value="Save" />&nbsp;<input type="reset" name="btnReset" id="btnStudentReset" value="Reset" /> 
 
\t \t \t <br /> \t \t \t 
 
\t \t \t You have inputed Name: {{Name}} & City: {{City}} 
 
\t \t </div> 
 
\t \t </form> 
 
\t </body> 
 
</html>

這是

angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to: 
Error: [$injector:nomod] Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. 
http://errors.angularjs.org/1.5.7/$injector/nomod?p0=myApp 

回答

0

你還沒有給我們提供完整的錯誤,我得到的錯誤,但最有可能的問題是,你錯過第二參數爲angular.module()

var app = angular.module("myApp", []); 

也僅供參考,您不應使用<script>元素的自閉標籤。您應該明確包含結束標記。此外,language屬性已被棄用,不需要type屬性時,腳本是JavaScript的:

<script src="Scripts/angular.js"></script> 
0

當你沒有提供完整的錯誤,我注意到你的錯誤,併爲您提供用於初始化Angular

一步一步1使index.html

<head> 
     <script type="text/javascript" language="javascript" src="lib/angular.js" /> 
     <script type="text/javascript" language="javascript" src="js/app.js" /> 

    </head> 
    <body ng-app="myApp"> 
     <form> 
     <div id="dvStudent" ng-controller="Student"> 
      <label>Name:</label> <input type="text" name="txtStudentName" id="txtStudentName" ng-model="Name" /> 
      <label>City:</label> <input type="text" name="txtStudentCity" id="txtStudentCity" ng-model="City" /> 
      <input type="button" name="btnSave" id="btnStudentSave" value="Save" /> 
      <input type="reset" name="btnReset" id="btnStudentReset" value="Reset" /> 
      <br />   
      <p>You have inputed Name: {{Name}} & City: {{City}} </p> 
     </div> 
     </form> 
    </body> 
</html> 

STEP 2讓兩個文件夾lib和LIB js地方角文件,並在app.js JS文件夾

app.js

var app = angular.module("myApp",[]); 
      app.controller("Student", funtion($scope){ 
       $scope.Name= 'Akshay'; 
       $scope.City: 'Mumbai';   
      }); 
+0

我張貼錯誤文本很抱歉,我的職位目前正與錯誤文本編輯。 –

相關問題