AngularJS-$ compileProvider.preAssignBindingsEnabled不是一个函数 [英] AngularJS -$compileProvider.preAssignBindingsEnabled is not a function

查看:86
本文介绍了AngularJS-$ compileProvider.preAssignBindingsEnabled不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在AngularJS(ver 1.6.10)应用程序上进行 gulp服务时收到以下错误消息:

I'm getting the following error message when attempting to do a gulp serve on my AngularJS (ver 1.6.10) app:

Error: [$injector:modulerr] Failed to instantiate module myAppName due to:
$compileProvider.preAssignBindingsEnabled is not a function
@http://localhost:9805/app/scripts/app.js:43:9
invoke@http://localhost:9805/lib/angular/angular.js:5108:16
runInvokeQueue@http://localhost:9805/lib/angular/angular.js:4997:11
loadModules/<@http://localhost:9805/lib/angular/angular.js:5007:11
forEach@http://localhost:9805/lib/angular/angular.js:387:11
loadModules@http://localhost:9805/lib/angular/angular.js:4987:5
createInjector@http://localhost:9805/lib/angular/angular.js:4904:19
doBootstrap@http://localhost:9805/lib/angular/angular.js:1936:20
bootstrap@http://localhost:9805/lib/angular/angular.js:1957:12
angularInit@http://localhost:9805/lib/angular/angular.js:1842:5
@http://localhost:9805/lib/angular/angular.js:35431:5
mightThrow@http://localhost:9805/lib/jquery/dist/jquery.js:3534:21

调用代码如下:

 /*
 * Main module of the application.
 */
angular
    .module('dataPipelineApp', [
        //various parameters
    ])
    .config(['$compileProvider', '$httpProvider', '$breadcrumbProvider', function ($compileProvider, $httpProvider, $breadcrumbProvider) {
        //initialize get if not there
        if (!$httpProvider.defaults.headers.get) {
            $httpProvider.defaults.headers.get = {};
        }
        $compileProvider.preAssignBindingsEnabled(true); //err here
    $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
    // extra
    $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
    $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

    $compileProvider.debugInfoEnabled(false); // speed up angular performance to not print debug info;
    $breadcrumbProvider.setOptions({
        templateUrl: 'app/views/headerBar.html'
    });
    //$httpProvider.defaults.headers.common['Access-Control-Allow-Origin'] = '*';
    $httpProvider.interceptors.push("AddToken");
    $httpProvider.interceptors.push("UnauthorizeInterceptor");
}])

类似的搜索似乎坚持认为这是版本差异。对这个问题进行类似的搜索似乎也表明angular-mocks的版本存在问题,但是我们根本没有使用角度模拟。我曾尝试将Angular降级为1.5.5,但其他搜索结果却表明您不能超过Angular,尽管我的所有同事都在Angular 1.6.10或更高版本上运行它。我也尝试过使用npm来安装angular-mocks,尽管它没有被使用,并且同步了版本以匹配我们的Angular的版本,但是无济于事。我真的不确定该怎么办,也不确定实际发生了什么,为什么它找不到该功能?

Similar searches seem to insist that this is a versioning discrepancy. Similar searches for this issue also seem to say there is an issue with the versioning of angular-mocks, however we are not using angular mocks at all. I have tried downgrading my Angular to 1.5.5, which other searches suggest you cannot exceed - despite all my colleagues running this on Angular 1.6.10 or higher. I have also tried using npm to install angular-mocks, despite being unused, and syncing the version to match that of our Angular, but to no avail. I'm really not sure what to do, nor am I sure what's actually happening, why can't it find that function?

编辑:我也在浏览器中检查了,通过运行 angular.version 搜索在控制台中进行搜索-尽管我重做了 gulp构建<在npm安装旧版本后,/ code>和 gulp注入服务。似乎没有正确选择正确的版本-强制降级的安装是否缺少我的东西?

I also checked in the browser, searching using the console by running a angular.version search - and it turns up 1.7.2 as my Angular version, despite me redoing gulp build and gulp inject serve after npm installing the older versions. It seems it isn't properly choosing the right version - is there something I'm missing to enforce the downgraded installations?

推荐答案

$ compileProvider.preAssignBindingsEnabled 标志已在AngularJS V1.6中弃用,并已从AngularJS V1.7中删除。

The $compileProvider.preAssignBindingsEnabled flag is deprecated in AngularJS V1.6 and has been removed from AngularJS V1.7.

AngularJS团队强烈建议迁移应用程序,使其不尽快依赖它。 AngularJS V1.6已于2018年7月1日终止生命。

The AngularJS team strongly recommends migrating your applications to not rely on it as soon as possible. AngularJS V1.6 went end-of-life on 1July2018.

来自文档:


由于 38f8c9 ,指令绑定在构造函数中不再可用。

Due to 38f8c9, directive bindings are no longer available in the constructor.

以前,<$ c $支持c> $ compileProvider.preAssignBindingsEnabled 标志。该标志控制绑定是在控制器构造函数内部可用还是仅在 $ onInit 挂钩中可用。绑定现在在构造函数中不再可用。

Previously, the $compileProvider.preAssignBindingsEnabled flag was supported. The flag controlled whether bindings were available inside the controller constructor or only in the $onInit hook. The bindings are now no longer available in the constructor.

要迁移代码:

  • If you specified $compileProvider.preAssignBindingsEnabled(true) you need to first migrate your code so that the flag can be flipped to false. The instructions on how to do that are available in the "Migrating from 1.5 to 1.6" guide. Afterwards, remove the $compileProvider.preAssignBindingsEnabled(true) statement.

< a href = https://docs.angularjs.org/guide/migration#-compile- rel = nofollow noreferrer>> AngularJS开发人员指南-迁移至V1.7-编译

从文档中:


由于 bcd0d4 会默认禁用组件/指令控制器实例上的预分配绑定,这意味着它们将不再在构造函数中可用。仍然可以重新打开它,这在迁移过程中会有所帮助。预分配绑定已被弃用,并将在以后的版本中删除,因此我们强烈建议迁移您的应用程序,使其不尽快依赖它。

Due to bcd0d4, pre-assigning bindings on component/directive controller instances is disabled by default, which means that they will no longer be available inside the constructors. It is still possible to turn it back on, which should help during the migration. Pre-assigning bindings has been deprecated and will be removed in a future version, so we strongly recommend migrating your applications to not rely on it as soon as possible.

初始化逻辑应放在控制器的 $ onInit()方法中,该方法确保在绑定完成后始终被调用

Initialization logic that relies on bindings being present should be put in the controller's $onInit() method, which is guaranteed to always be called after the bindings have been assigned.

— AngularJS开发人员指南-迁移至1.6-编译



注意:



2018年7月1日,对AngularJS 1.6的支持终止。有关更多信息,请参见 AngularJS MISC-版本支持状态

这篇关于AngularJS-$ compileProvider.preAssignBindingsEnabled不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆