AngularJS 1.5错误引导IBM Mobilefirst

时间:2022-11-11 22:14:31

I seem to have problems combining an MFP hybrid (no cordova) application and angular 1.5. The same application with angular 1.4.9 works fine, but if I switch to angular1.5 then i get this error:

我似乎在组合MFP混合(无Cordova)应用和角1.5时遇到了问题。角度1.4.9的相同应用程序工作正常,但如果我切换到angular1.5然后我得到此错误:

Error: [$injector:modulerr] Failed to instantiate module ng due to:
TypeError: Cannot set property 'aHrefSanitizationWhitelist' of null
at $$SanitizeUriProvider (http://localhost:10080/Hybrid/apps/services/preview/HelloWorld/android/1.0/default/vendor/angular5.js:17272:35)
at new <anonymous> (http://localhost:10080/Hybrid/apps/services/preview/HelloWorld/android/1.0/default/worklight/worklight.js:1033:23)
at Object.instantiate (http://localhost:10080/Hybrid/apps/services/preview/HelloWorld/android/1.0/default/vendor/angular5.js:4621:14)
at provider (http://localhost:10080/Hybrid/apps/services/preview/HelloWorld/android/1.0/default/vendor/angular5.js:4435:36)
at http://localhost:10080/Hybrid/apps/services/preview/HelloWorld/android/1.0/default/vendor/angular5.js:367:32
at forEach (http://localhost:10080/Hybrid/apps/services/preview/HelloWorld/android/1.0/default/vendor/angular5.js:337:20)
at Object.provider (http://localhost:10080/Hybrid/apps/services/preview/HelloWorld/android/1.0/default/vendor/angular5.js:4425:9)
at ngModule (http://localhost:10080/Hybrid/apps/services/preview/HelloWorld/android/1.0/default/vendor/angular5.js:2476:16)
at Object.invoke (http://localhost:10080/Hybrid/apps/services/preview/HelloWorld/android/1.0/default/vendor/angular5.js:4606:19)
at runInvokeQueue (http://localhost:10080/Hybrid/apps/services/preview/HelloWorld/android/1.0/default/vendor/angular5.js:4499:35)
http://errors.angularjs.org/1.5.0/$injector/modulerr?p0=ng&p1=TypeError%3A%…%2FHelloWorld%2Fandroid%2F1.0%2Fdefault%2Fvendor%2Fangular5.js%3A4499%3A35)

anyone a clue what it could be?

谁知道它可能是什么?

3 个解决方案

#1


3  

I had the exact same problem when I upgraded to angular 1.5.0.
The problem turned out to be with a custom implementation of Function.prototype.bind that we had in our code, it looks like this interfered with the one defined in angular.

当我升级到1.5.0角时,我遇到了完全相同的问题。问题结果是我们在代码中使用的Function.prototype.bind的自定义实现,看起来这干扰了在angular中定义的那个。

Take at the second line on your error callstack

在错误调用堆栈的第二行

at new <anonymous> (http://localhost:10080/Hybrid/apps/services/preview/HelloWorld/android/1.0/default/worklight/worklight.js:1033:23)

I think worklight.js may have an implementation of prototype.bind which is incompatible with the one in angular (see https://code.angularjs.org/1.5.0/docs/api/ng/function/angular.bind)

我认为worklight.js可能有一个prototype.bind的实现,它与angular中的那个不兼容(参见https://code.angularjs.org/1.5.0/docs/api/ng/function/angular.bind)

#2


0  

Also seeing this on the MFP 8.0 cordova plugin.

也可以在MFP 8.0 cordova插件上看到这一点。

#3


0  

As others have mentioned, this can be caused by polyfills for Function.prototype.bind. In particular, it seems to be caused by ones that don't properly handle calling the function as a constructor with new. Simple implementations may always return the bound object regardless of invocation, whereas the expectation is that the new operator prevails over the binding and the newly created object gets returned instead.

正如其他人所提到的,这可能是由Function.prototype.bind的polyfill造成的。特别是,它似乎是由那些没有正确处理函数作为new的构造函数的函数引起的。无论调用如何,简单实现总是可以返回绑定对象,而期望是新操作符优先于绑定,而是返回新创建的对象。

eg.

例如。

// create an object to bind to
var alt = {
    message: 'I am the alternate'
};

// our function
function myFunc() { 
   console.log( this.message );
};

// bind our alternate object to this for myFunc
myFunc.bind( alt );

Standard Invocation Runs as Expected

标准调用按预期运行

myFunc(); // output 'I am the alternate'

Invocation via new not as Expected (this is the one that breaks angular 1.5)

通过new调用不是按预期的(这是打破角度1.5的那个)

new myFunc(); // also outputs 'I am the alternate'</jscodeblock>

The expected behavior is that new invocation will return a new object and not the bound one.

预期的行为是新调用将返回一个新对象,而不是绑定的对象。

If you need a polyfill for Function.prototype.bind be sure it properly handles this scenario such as the one found on MDN.

如果需要Function.prototype.bind的polyfill,请确保它正确处理此场景,例如在MDN上找到的场景。

#1


3  

I had the exact same problem when I upgraded to angular 1.5.0.
The problem turned out to be with a custom implementation of Function.prototype.bind that we had in our code, it looks like this interfered with the one defined in angular.

当我升级到1.5.0角时,我遇到了完全相同的问题。问题结果是我们在代码中使用的Function.prototype.bind的自定义实现,看起来这干扰了在angular中定义的那个。

Take at the second line on your error callstack

在错误调用堆栈的第二行

at new <anonymous> (http://localhost:10080/Hybrid/apps/services/preview/HelloWorld/android/1.0/default/worklight/worklight.js:1033:23)

I think worklight.js may have an implementation of prototype.bind which is incompatible with the one in angular (see https://code.angularjs.org/1.5.0/docs/api/ng/function/angular.bind)

我认为worklight.js可能有一个prototype.bind的实现,它与angular中的那个不兼容(参见https://code.angularjs.org/1.5.0/docs/api/ng/function/angular.bind)

#2


0  

Also seeing this on the MFP 8.0 cordova plugin.

也可以在MFP 8.0 cordova插件上看到这一点。

#3


0  

As others have mentioned, this can be caused by polyfills for Function.prototype.bind. In particular, it seems to be caused by ones that don't properly handle calling the function as a constructor with new. Simple implementations may always return the bound object regardless of invocation, whereas the expectation is that the new operator prevails over the binding and the newly created object gets returned instead.

正如其他人所提到的,这可能是由Function.prototype.bind的polyfill造成的。特别是,它似乎是由那些没有正确处理函数作为new的构造函数的函数引起的。无论调用如何,简单实现总是可以返回绑定对象,而期望是新操作符优先于绑定,而是返回新创建的对象。

eg.

例如。

// create an object to bind to
var alt = {
    message: 'I am the alternate'
};

// our function
function myFunc() { 
   console.log( this.message );
};

// bind our alternate object to this for myFunc
myFunc.bind( alt );

Standard Invocation Runs as Expected

标准调用按预期运行

myFunc(); // output 'I am the alternate'

Invocation via new not as Expected (this is the one that breaks angular 1.5)

通过new调用不是按预期的(这是打破角度1.5的那个)

new myFunc(); // also outputs 'I am the alternate'</jscodeblock>

The expected behavior is that new invocation will return a new object and not the bound one.

预期的行为是新调用将返回一个新对象,而不是绑定的对象。

If you need a polyfill for Function.prototype.bind be sure it properly handles this scenario such as the one found on MDN.

如果需要Function.prototype.bind的polyfill,请确保它正确处理此场景,例如在MDN上找到的场景。