我的Breeze脚本上已弃用方法的版本问题

时间:2014-03-01 18:51:55

标签: angularjs breeze q hottowel

尝试在John Papa Pluralsight Video教程中实现会话部分时。 我收到以下错误:

  

未捕获的TypeError:对象#没有方法'extendQ'

(function () {
    'use strict';

    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
        'ui.bootstrap',      // ui-bootstrap (ex: carousel, pagination, dialog)
        //'breeze.angular.q'
    ]);

    // Handle routing errors and success events
    app.run(['$route', '$rootScope', '$q', function ($route, $rootScope, $q) {
        // Include $route to kick start the router.
        breeze.core.extendQ($rootScope, $q);
        //use$q($rootScope,$q);

    }]);        
})();

重要的是要知道我正在处理的微风版本比原始视频上使用的版本更新。

我在breeze website上搜索了一些答案,我发现了这个:

  

$ q已被弃用。它被Breeze Angular Service取代。

但是我没有在教程示例中使用它。如何使用新的实现更改已弃用的实现?

更新:

此链接有助于解决问题:

http://www.breezejs.com/documentation/breeze-angular-service

2 个答案:

答案 0 :(得分:6)

微风库已更新,答案在此链接上:http://www.breezejs.com/documentation/breeze-angular-service

具体来自帖子底部的代码:

迁移非常轻松。

  1. 从项目中删除breeze.angular.q.js脚本。
  2. 如果您使用NuGet,请卸载 - 包装Breeze.Angular.Q。
  3. 按照上面的说明安装breeze.angular.js。
  4. 更新您的index.html,将breeze.angular.q.js更改为breeze.angular.js。
  5. 更新您的应用模块以依赖“breeze.angular”。
  6. 在代码中找到一个名为“use $ q”的地方,并将其替换为“breeze”依赖项。
  7. 例如,你可能会这样:

    var app = angular.module('app', [
       // ... other dependencies ...
       'breeze.angular.q' // tells breeze to use $q instead of Q.js
    ]);
    
    app.run(['$q','use$q', function ($q, use$q) {
           use$q($q);
    }]);
    

    到此:

    var app = angular.module('app', [
       // ... other dependencies ...
       'breeze.angular'
    ]);
    
    app.run(['breeze', function () { }]);
    

    您还应该追踪并消除配置Breeze以使用“backingStore”模型库适配器和$ http的代码。例如,你可以这样做:

    function configBreeze($q, $http, use$q) {
        // use $q for promises
        use$q($q);
    
        // use the current module's $http for ajax calls
        var ajax = breeze.config.initializeAdapterInstance('ajax', 'angular');
        ajax.setHttp($http);
    
        // the native Breeze 'backingStore' works for Angular
        breeze.config.initializeAdapterInstance('modelLibrary', 'backingStore', true);
    
        breeze.NamingConvention.camelCase.setAsDefault();
    }
    

    到此:

    function configBreeze() {
        breeze.NamingConvention.camelCase.setAsDefault();
    

答案 1 :(得分:4)

在John Papa拍摄the same course时,我也点击了步骤4.10中没有的breeze.core.extendQ

这就是我为解决这个问题所做的工作:

1 - 直接app.js传递breeze依赖:

// Handle routing errors and success events
// Trigger breeze configuration
app.run(['$route', 'breeze', function($route, breeze)
{
    // Include $route to kick start the router.
}]);

2 - 在datacontext.js执行:

return EntityQuery.from('Sessions')
    .select('id, title, code, speakerId, trackId, timeSlotId, roomId, level, tags')
    .orderBy(orderBy)
    .toType('Session')
    .using(manager).execute()
    .then(querySucceeded, _queryFailed);

您还可以从index.html中删除breeze.to $ q.shim.js并从项目中的\Scripts文件夹中删除该文件,因为它不再需要了。< / p>


这是我现在正在做的同一项目的updated source code [包括修正]。

相关问题