Когда я пытаюсь ввести одну или несколько моделей, используя служебную директиву в отдельный файл сценария java, я становлюсь ниже ошибки, но он работает в одном файле Javascript. Здесь клиент - модель
Ошибка:
Msgstr "Binding.js: 33 Uncaught ReferenceError: Клиент не определен". Binding.js: 9 Uncaught ReferenceError: Клиент не определен (анонимная функция) @Binding.js: 9 angular.js: 13424 Ошибка: [$ injector: unpr] Неизвестный поставщик: customerProvider <- customer <- myCustomerController
Ниже мой код:
Модель (customer.js):
function Customer() {
this.customerName = "David";
this.customerCode = "C001";
}
Код привязки (Binding.js)
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: Model: Customer.js
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>
Прежде чем использовать эту услугу, вы должны сначала ввести службу в свой контроллер.
BindingCode.$inject = ['Customer']
Переустановите customer.js в
var myCustomerApp = angular.module("myCustomerApp", []);
myCustomerApp.service('customer', Customer);
function Customer() {
this.customerName = "David";
this.customerCode = "C001";
}
Перегруппируйте Binding.js в
var myCustomerApp = angular.module("myCustomerApp", []);
myCustomerApp.controller("myCustomerController", BindingCode);
BindingCode.$inject = ['Customer']
function BindingCode($scope,Customer) {
$scope.customer = Customer;
}
добавьте <script src="Scripts/customer.js"></script>
в файл customer.html
customer.js
на странице?