我正在将entityManagerFactory注入Angular,但是我收到了一个错误.正如John Papa的例子一样,这在datacontext模块中完成.错误是未知的提供者.我在index.html文件中包含了entityManagerFactory.js文件但没有成功.有任何想法吗?
function () {
'use strict';
var serviceId = 'datacontext';
angular.module('app').factory(serviceId, ['common', 'entityManagerFactory', 'breeze', 'logger', datacontext]);
function datacontext(common) {
var $q = common.$q;
var service = {
getPeople: getPeople,
getMessageCount: getMessageCount
};
}
}
Run Code Online (Sandbox Code Playgroud)
小智 7
我有同样的错误,解决方案很简单,并在John Papas博客中记录.
在index.html文件中,确保您引用了所有必需的源文件,并且它们以正确的顺序加载.
<link href="content/breeze.directives.css" rel="stylesheet" />
<script src="scripts/breeze.debug.js"></script>
<script src="scripts/breeze.angular.js"></script>
<script src="scripts/breeze.directives.js"></script>
<script src="scripts/breeze.saveErrorExtensions.js"></script>
<script src="scripts/breeze.to$q.shim.js"></script> <!-- Needed only if you are using to$q -->
<script src="app/app.js"></script>
...
...
<script src="app/services/entityManagerFactory.js"></script>
Run Code Online (Sandbox Code Playgroud)
确保在entityManagerFactory.js之前加载了app.js.
不要忘记在app.js中包含对breeze模块的引用.
var app = angular.module('app', [
// Angular modules
'ngAnimate', // animations
'ngRoute', // routing
'ngSanitize', // sanitizes html bindings (ex: sidebar.js)
// Custom modules
'common', // common functions, logger, spinner
'common.bootstrap', // bootstrap dialog wrapper functions
// 3rd Party Modules
'breeze.angular', // configures breeze for an angular app
'breeze.directives', // contains the breeze validation directive (zValidate)
'ui.bootstrap' // ui-bootstrap (ex: carousel, pagination, dialog)
]);
Run Code Online (Sandbox Code Playgroud)
如果您使用 HotTowel.Angular.Breeze 版本 2.2.0 启动了一个新项目,那么您面临的问题实际上可能是由entityManagerFactory 注入的 BreezeProvider 的问题。
如果是这种情况,您应该会看到以下错误:
未知提供者:breezeProvider <- 微风 <-entityManagerFactory <- datacontext
要解决此问题,请确保已将“breeze.angular.js”和“breeze.directives.js”添加到index.html,并将“breeze.angular”和“breeze.directives”添加到app.js。
这将允许 Angular 将breezeProvider注入entityManagerFactory,然后它应该能够成功注入到您的数据上下文中。
此外,您可能会发现脚本文件夹中缺少breeze.directives.js,而只有breeze.directives.validation.js。这似乎是 HotTowel.Angular.Breeze v2.2.0 Nuget 包的问题。您可以通过使用 Nuget 安装 Breeze.Angular.Directives v1.3.6 来解决此问题。
PM> 安装包 Breeze.angular.directives
有关此问题的更多信息和详细说明,请访问 John Papa 的博客:http://www.johnpapa.net/new-breeze-angular-service/
| 归档时间: |
|
| 查看次数: |
1440 次 |
| 最近记录: |