Angular not working on IE9 possibly due to internal injector? - javascript

I have a angular 1.3.15 application which doesn't work on Internet Explorer 9, I get a Unable to get property 'replace' of undefined or null reference error which points to this block of code in the angular core.
The error is thrown that much is executed correctly but I have no ideea what this function normally does and what's missing on IE9 for it to work.
function createInternalInjector(cache, factory) {
function getService(serviceName, caller) {
if (cache.hasOwnProperty(serviceName)) {
if (cache[serviceName] === INSTANTIATING) {
throw $injectorMinErr('cdep', 'Circular dependency found: {0}',
serviceName + ' <- ' + path.join(' <- '));
}
return cache[serviceName];
} else {
try {
path.unshift(serviceName);
cache[serviceName] = INSTANTIATING;
return cache[serviceName] = factory(serviceName, caller);
} catch (err) {
if (cache[serviceName] === INSTANTIATING) {
delete cache[serviceName];
}
throw err;
} finally {
path.shift();
}
}
}
As a final note I've included es5-shim and shams, I already use data-ng-* attributes I've read multiple articles about getting angular to work on IE9 but none of them describe a problem similar to this one so I'm left with only asking this question on SO.

So I found the issue by adding breakpoints and debugging till I found the name of the service it couldn't inject $location and this stemmed from me trying to use html5 mode:
$locationProvider.html5Mode(true).hashPrefix('!');
If I comment this and use the # routes the application works as far as I can tell, if anyone has a ideea on how to use html5mode in IE9 I'll mark your answer as the correct one as I don't want to answer my own question.

Related

How to fix "Undefined is not an object" error in Javascript

I am trying to use scripts in illustrator. Some of these require being able to import other scripts so I found the below code. When I try to run it I receive
Error 21: Undefined is not an object.
Line 6 -> var Libraries = (function(libpath){"
I have looked through other answers and it seems the issue is that "Libraries" (?) is undefined, and that I ought to define it first. Sadly I don't know what it ought to be defined as. Or I don't understand the problem in general.
I expected it to import helloworld.jsx and hence be able to run the helloWorld function. It threw up the error described above.
//Library importing function from https://gist.github.com/jasonrhodes/5286526
// indexOf polyfill from https://gist.github.com/atk/1034425
[].indexOf||(Array.prototype.indexOf=function(a,b,c){for(c=this.length,b=(c+~~b)%c;b<c&&(!(b in this)||this[b]!==a);b++);return b^c?b:-1;});
var Libraries = (function(libPath) {
return {
include: function(path) {
if (!path.match(/\.jsx$/i)) {
path = path + ".jsx";
}
return $.evalFile(libPath + path);
}
};
})($.fileName.split("/").splice(0,$.fileName.split("/").indexOf("adobe_scripts") + 1).join("/") + "/lib/");
Libraries.include("HelloWorld.jsx");
helloWorld();
It's many moons since I did this stuff ...
Isn't Libraries a function that takes a libPath, so you would need to call
Libraries('c:\whereever').include('HellowWorld.jsx');

Unable to set property...of undefined or null reference

I inherited a SharePoint site that deploys several apps. Everything had been working fine for a year and out of no where all the apps stopped loading and I used developer tools in IE11 and got the following: "SCRIPT5007: Unable to set property 'relatedNavigationProperty' of undefined or null reference". This is the first time I've used angular so I'm not great with it. The file I'm looking at doesn't even have a 'relatedNavigationProperty' property. I've been scouring the web for hours trying to figure this out to no avail. Any suggestions for what I should be looking for would be greatly appreciated.
Looked through all related scripts for relatedNavigationProperty
Checked Emulation information- Document mode = 11
Verified that this is an issue for all users
function createInternalInjector(cache, factory) {
function getService(serviceName) {
if (cache.hasOwnProperty(serviceName)) {
if (cache[serviceName] === INSTANTIATING) {
throw $injectorMinErr('cdep', 'Circular dependency found: {0}',
serviceName + ' <- ' + path.join(' <- '));
}
return cache[serviceName];
} else {
try {
path.unshift(serviceName);
cache[serviceName] = INSTANTIATING;
return cache[serviceName] = factory(serviceName);
} catch (err) {
if (cache[serviceName] === INSTANTIATING) {
delete cache[serviceName];
}
throw err;
} finally {
path.shift();
}
}
}
I expect apps to be loading and working as they previously were but the landing page loads and will not continue on to the apps
Developer tools throws the error at the 'throw err' line...obviously
This error Unable to set propertyrelatedNavigationPropertyof undefined or null reference implies that the property called relatedNavigationProperty is being set on a variable that has a value of undefined or null.
For example:
undefined.myProp = true;
null.myProp = true;
You need to log out the values of cache, factory, and any other variables in that code to see what's happening. relatedNavigationProperty is probably being passed in.

this.hasErrors is not a function

I searched for a solution to my problem online but couldn't find any appropriate answer. Although there are tons of this particular question online.
In my typescript file I have the following three methods:
hasErrors() {
// Checking for errors
}
saveItem() {
if (this.hasErrors())
return;
// Save item
}
sendItemToAuthority() {
if (this.hasErrors())
return;
// Send item to authority
}
Somehow this.hasErrors() inside sendItemToAuthority() isn't recognized as a function but in saveItem() it works without any problem. I get the following error in chrome developer tools:
this.hasErrors is not a function
I found following possibility which didn't work for me either (same error message):
sendItemToAuthority() {
var self = this;
if (self.hasErrors)
return;
// Send item to authority
}
Could anyone lead me to a solution? I really don't get why it isn't working.
saveItem() it works without any problem. I get the following error in chrome developer tools this.hasErrors is not a function
You most likely have the wrong this. Use an arrrow function : https://basarat.gitbooks.io/typescript/content/docs/arrow-functions.html
I finally found a solution. In my constructor I had
this.saveItem = this.saveItem.bind(this);
but forgot to add
this.sendItemToAuthority = this.sendItemToAuthority.bind(this);

PEG.js: how to use prompt?

I'm creating a C++ parser with PEG.js, and I need to be able to use cin. With the after-match JS, when I use prompt(), the (alternate) online version throws an error of 'Parse Error: prompt is not defined'. I am trying to use the initializer to create a function to replicate prompt (probably not optimized, I was just trying it as a solution). However, when I do this, it still gives me the error. I have tried using window.prompt as well, but again, it does not work. Here's an example of what I'm doing:
{
function cin() {
window.prompt("");
}
function changeVar(variable, newValue) {
if(typeof variable === typeof newValue) {
variable = newValue;
} else if(typeof variable === 'undefined') {
alert("You can't assign a value to a variable if the variable isn't declared yet!");
} else {
alert("Bad assignment. In C++, a variable *must* have the same type *all the time*.");
}
}
}
stdin =
whitespace* "std::cin" whitespace* ">>" whitespace* varToBeChanged:[a-zA-Z_]+ ";" whitespace*
{ changeVar(varToBeChanged, cin('')); return varToBeChanged; }
whitespace =
space:[ \t]
{ return space; }
and then in the parser testing field:
std::cin >> variable;
Thank you for looking. I have tried Googling this and SO-searching this but I haven't found any results.
Also, here is the main piece of code, for all the (current) extra information anyone needs. I am having some problems with this as well, but I'll try to figure them out on my own before I post another question.
If you are using http://peg.arcanis.fr/, then the parser code is executed inside of a Web Worker - which has no access to any UI like the window or the DOM. The error "undefined variable" means literally that there is no window or prompt declared.
If you paste your code into http://pegjs.majda.cz/online, it is executed in the web page environment and works flawlessly.

IE8 gives error "Invalid argument" when using prototype.js, how do I find where the error is?

I have a fairly complex piece of Javascript that works flawlessly with no errors in Google Chrome, Firefox, Safari, and Opera. However, as tends to always be the endlessly annoying case, it completely fails in Internet Explorer. I have tested in IE7 and IE8 and get the same error:
Invalid argument. prototype.js, line
2216, character 9
I am using Prototype 1.6.1 hosted through Google. The error given isn't very helpful since it doesn't tell me where in my actual code the error is occurring. The line mentioned in the error is the 6th line from the bottom in the following code:
setStyle: function(element, styles) {
element = $(element);
var elementStyle = element.style, match;
if (Object.isString(styles)) {
element.style.cssText += ';' + styles;
return styles.include('opacity') ?
element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element;
}
for (var property in styles)
if (property == 'opacity') element.setOpacity(styles[property]);
else
elementStyle[(property == 'float' || property == 'cssFloat') ?
(Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :
property] = styles[property];
return element;
},
Since it is in the setStyle block of code, I assume the error occurs when I am setting style attributes for some element. However, I call setStyle over 100 times in this script and have been trying to figure out where exactly the error is occurring for several hours. Is there anything I can do to help myself in finding where the error is occurring?
Put an explicit try ... catch around the code:
for (var property in styles) {
try {
if (property == 'opacity') element.setOpacity(styles[property]);
else
elementStyle[(property == 'float' || property == 'cssFloat') ?
(Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :
property] = styles[property];
}
catch (_) {
throw "Error setting property '" + property + "' to value '" + styles[property] + "'";
}
}
Then you'll know exactly what property and value is causing the problem.
In IE8 enable the developer tool to break on error [5th button on the script tab.] Click the Start Debugging button.
When the error occurs, you should be able to inspect the varaibles and see what is causing the problem exactly.
Try debugging with Microsoft® Visual Web Developer® 2010 Express, it's free and very easy to use while debugging on IE.
You've already marked your chosen answer so have probably found the cause by now. The line in question concerns setting opacity (which IE handles as it's proprietary filter) so I suggest looking for calls to setStyle that set an opacity, perhaps ones that set an unusual value.
The problem is caused by setStyle({someProperty: null}).
Maybe also undefined or something kind of.
To investigate such problems in future, inspect arguments you give to third-party functions in catch block. Kind of
try{
element.setStyle({someProperty: someValue})
}catch(error){
throw('' + someProperty + ':' + someValue)
}
This code would have pointed you to the source of the error in zero time. Here is more detailed snippet for debugging this case using some Prototype.js' helpers:
;(function () {
var superFunction = Element.setStyle
Element.addMethods({
setStyle: function (element, _arguments) {
try{
superFunction(element, _arguments)
}catch(error){
console.log(error, $H(_arguments).inspect())
}
}
})
})()
P.S. in IE8 you should open Developer Tools (F12) to have console working.

Categories