javascript语法错误的两个未捕获错误
我用angularjs编写简单的代码,我将面临以下两个错误:javascript语法错误的两个未捕获错误,javascript,angularjs,Javascript,Angularjs,我用angularjs编写简单的代码,我将面临以下两个错误: Uncaught SyntaxError: Unexpected token ) Uncaught Error: [$injector:modulerr] 我的html文件是这样的 <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title>Invoice1</ti
Uncaught SyntaxError: Unexpected token )
Uncaught Error: [$injector:modulerr]
我的html文件是这样的
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Invoice1</title>
<script type="text/javascript" src="angular.min.js" ></script>
<script type="text/javascript" src="invoice1.js" ></script>
</head>
<body>
<div ng-app="invoice1" ng-controller="InvoiceController as invoice">
<b>Invoice</b>
<div>
Quantity:<input type="number" min="0" ng-model="invoice.qant" required >
</div>
<div>
Cost:<input type="number" min="0" ng-model="invoice.cost" required />
<select ng-model=invoice.incurr>
<option ng-repeat="c in invoice.currencies">{{c}}</option>
</select>
</div>
<div>
<b>Total:</b>
<span ng-repeat="c in invoice.currencies">
{{invoice.total(c)|currency:c}}
</span>
<button ng-click="invoice.pay()">Pay</button>
</div>
</div>
</body>
</html>
(function(angular)){
'use strict';
angular.module('invoice1',[])
.controller('InvoiceController',function()){
this.qant=1;
this.cost=2;
this.incurr='EUR';
this.currencies=['USD','EUR','CNY'];
this.usdToForeignRates={
USD:1,
EUR:0.79,
CNY:6.09
};
this.total=function.total(outcurr){
return this.convertCurrency(this.qant * this.cost, this.incurr,outcurr);
};
this.convertCurrency=function convertCurrency(amount,incurr,outcurr){
return amount * this.usdToForeignRates[outcurr]/this.usdToForeignRates[incurr]
};
this.pay=function pay(){
window.alert("Thanx! check your currency");
};
});
})(window.angular);
//window.alert("thanx!");
关于您的
Uncaught语法错误:意外标记)
this.pay=function pay(){
window.alert("Thanx! check your currency");
};
}) //<----this here doesnt have a matching "(" ;
}) //----this here doesnt have a matching "(" (window.angular);
this.pay=函数pay(){
警告(“Thanx!检查您的货币”);
};
})//您的代码充满了错误。这里没有
(函数(角度))
.controller('InvoiceController',function()){
- 不要使用
函数。总计
使用一些IDE或在线工具,如
如果你希望得到任何帮助,你真的需要格式化你的代码。
(function(angular)) <----
.controller('InvoiceController',function()) <----
(function(angular){
'use strict';
angular.module('invoice1',[])
.controller('InvoiceController',function(){
this.qant=1;
this.cost=2;
this.incurr='EUR';
this.currencies=['USD','EUR','CNY'];
this.usdToForeignRates={
USD:1,
EUR:0.79,
CNY:6.09
};
this.total=function (outcurr){
return this.convertCurrency(this.qant * this.cost, this.incurr,outcurr);
};
this.convertCurrency=function convertCurrency(amount,incurr,outcurr){
return amount * this.usdToForeignRates[outcurr]/this.usdToForeignRates[incurr];
};
this.pay=function pay(){
window.alert("Thanx! check your currency");
};
});
})(window.angular);