Hot Towel Angular-Breeze课程 - 获取breezeProvider错误

时间:2014-06-10 15:41:18

标签: angularjs breeze datacontext hottowel

我正在遵循John Papa的课程中的每一步,用Angular和Breeze构建应用程序 - 第1部分。 一旦我完成了标题为“通过你的应用程序创建垂直切片”的模块“开始播放”,我就开始出现 breezeProvider错误

请在下面找到错误图片以及datacontext。 js代码。

非常感谢您的建议。

                  -------------------------------------------

在F12 Dev Tools中,控制台错误是:

未捕获错误:找不到breeze localhost:1772 / Scripts / breeze.angular.js:90 [贝壳]热毛巾角装!空

错误:[$ injector:unpr]未知提供者:breezeProvider < - breeze< - entityManagerFactory< - datacontext

[app] [CC Error] [$ injector:unpr]未知提供者:breezeProvider< - breeze< - entityManagerFactory< - datacontext

Breeze error

这是我的datacontext.js代码:

(function () {
 'use strict';

var serviceId = 'datacontext';
angular.module('app').factory(serviceId, ['common', 'entityManagerFactory', datacontext]);

function datacontext(common, emFactory) {   // emFactory param refers to 'entityManagerFactory'
    var EntityQuery = breeze.EntityQuery;
    var getLogFn = common.logger.getLogFn;  
    var log = getLogFn(serviceId);          // see common\logger.js
    var logError = getLogFn(serviceId, 'error');
    var logSuccess = getLogFn(serviceId, 'success');
    var manager = emFactory.newManager();           // COMES FROM entityManagerFactory.js
    var $q = common.$q;

    var service = {
        getPeople: getPeople,
        getMessageCount: getMessageCount,
        getSessionPartials: getSessionPartials
    };

    return service;

    function getMessageCount() { return $q.when(72); }

    function getPeople() {
        var people = [
            { firstName: 'John', lastName: 'Papa', age: 25, location: 'Florida' },
            { firstName: 'Ward', lastName: 'Bell', age: 31, location: 'California' },
            { firstName: 'Colleen', lastName: 'Jones', age: 21, location: 'New York' },
            { firstName: 'Madelyn', lastName: 'Green', age: 18, location: 'North Dakota' },
            { firstName: 'Ella', lastName: 'Jobs', age: 18, location: 'South Dakota' },
            { firstName: 'Landon', lastName: 'Gates', age: 11, location: 'South Carolina' },
            { firstName: 'Haley', lastName: 'Guthrie', age: 35, location: 'Wyoming' }
        ];
        return $q.when(people);
    }

    function getSessionPartials() {            
        var orderBy = 'timeSlotId, level, speaker.firstName';
        var sessions;

        // use Breeze to get data from back end; see datacontext() function above for init code.
        return EntityQuery.from('Sessions')
            .select('id, title, code, speakerId, trackId, timeSlotId, roomId, level, tags')
            .orderBy(orderBy)
            .toType('Session')              // cast to type 'Session' (in CC.Model project)
            .using(manager).execute()       //  communicate to back end
            .then(querySucceeded, _queryFailed);
            //.to$q(querySucceeded, _queryFailed);   // OLD WAY: converts promise to Ang.

        function querySucceeded(data) {
            session = data.results;
            log('Retrieved Session Partials from remote data source', sessions.length, true);
            return sessions;
        }
        function _queryFailed(error) {  // PASSED IN BY BREEZE
            var msg = config.appErrorPrefix + 'Error retrieving data.' + error.message;  
            logError(msg, error);
            throw error;
        }
    }
 }

})();

2 个答案:

答案 0 :(得分:5)

真正的问题是第一个错误:Can't find breeze。看到breeze.angular.js是咆哮的文件......

确保在index.html

中添加了breeze JS文件
<script src="scripts/breeze.debug.js"></script> // or breeze.min.js
<script src="scripts/breeze.angular.js"></script>

如果您已添加,请确保它在breeze.angular.js之前显示,如上所示。


这些是我在我的应用中的breeze JS引用:

<!-- #region Breeze -->
<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>
<!-- #endregion -->

答案 1 :(得分:1)

确保包含将breeze服务作为依赖项包含在模块定义中:

var app = angular.module('app', [
    'ngAnimate',        
    'ngRoute',          
    'ngSanitize',       

    'breeze.angular',   // THIS IS THE MISSING DEPENDENCY

    'common',           
    'common.bootstrap', 

    'ui.bootstrap'      
]);

并确保包含这些文件:

<script src="Scripts/breeze.debug.js"></script>
<script src="Scripts/breeze.bridge.angular.js"></script>
<script src="Scripts/breeze.directives.js"></script>
<script src="Scripts/breeze.saveErrorExtensions.js"></script>