別のJavaスクリプトファイルにserviceディレクティブを使用して単一または複数のモデルを挿入しようとしているときにエラーが発生していますが、単一のJavascriptファイル。ここでは顧客がモデルです単一または複数モデルangularJsの別々のjavascriptファイルでserviceディレクティブを使用してInjecting
エラー:
"Binding.js:33キャッチされないにReferenceError:お客様が定義されていません"。 Binding.js:9キャッチされないにReferenceError:お客様が定義されていないBinding.js @(匿名関数):9 angular.js:13424エラー:[$インジェクター:UNPR]不明プロバイダ:customerProvider < - 顧客< - myCustomerController
以下は私のコードです:
モデル(customer.js):コード(Binding.js)01バインディング
function Customer() {
this.customerName = "David";
this.customerCode = "C001";
}
function BindingCode($scope,customer) {
$scope.customer = customer;
}
var myCustomerApp = angular.module("myCustomerApp", []);
myCustomerApp.controller("myCustomerController", BindingCode);
myCustomerApp.service('customer', Customer);
コードの表示(customer.html)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Scripts/angular.js"></script>
<script src="Scripts/Binding.js"></script>
</head>
<body ng-app="myCustomerApp">
<div ng-controller="myCustomerController">
<table>
<tr>
<td>
CustomerName
</td>
<td>
<input type=text id="CustomerName" ng-model="customer.customerName" /><br />
</td>
</tr>
<tr>
<td>
CustomerCode
</td>
<td>
<input type=text id="CustomerCode" ng-model="customer.customerCode" />
</td>
</tr>
</table>
</div>
しかし、同じコードがここでの唯一のモデルとビューを作業してcustomer.htmlにセクションスクリプトに含まれるコードをバインドされています。 モデル:Customer.js
あなたが最初にそのサービスをがyousing前に、コントローラにサービスを注入する必要がありfunction Customer() {
this.customerName = "David";
this.customerCode = "C001";
}
ビューコード(customer.html)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Scripts/angular.js"></script>
<script src="Scripts/CustomerModle.js"></script>
</head>
<script>
function BindingCode($scope, customer) {
$scope.customer = customer;
}
var myCustomerApp = angular.module("myCustomerApp", []);
myCustomerApp.controller("myCustomerController", BindingCode);
myCustomerApp.service('customer', Customer);
</script>
<body ng-app="myCustomerApp">
<div ng-controller="myCustomerController">
</div>
</body>
</html>
これはAngular2とどのように関連していますか? –
あなたは 'customer.js'をページに入れましたか? –
私はそれを含める必要があります – sudhir