I created a computed observable rather than having a extra code in the view and now when I run the page I get an error in the console stating:
"Uncaught TypeError: Cannot read property 'concat' of undefined"
Here is what I have so far:
self.email = ko.observable(initialData.userEmail || '');
self.emailMailto = ko.computed(function(){ return 'mailto:'+self.email();});
I know that email observable is returning the appropriate data but I am not sure if it is referring to emailMailto as undefined.
this is my view:
<p><a data-bind="attr:{href:emailMailto},text:email"></a></p>
The code you've posted is not directly related to your problem.
What's happening here is that some code wants to use the .concat() method on a variable.
.concat() is a prototype of Array, which means that the code in question expects an array.
undefined means that, instead of an array, nothing has been passed to the code. This can mean two things:
Either an expected function parameter has not been passed, e.g. the method is declared as function doSomething(withValue) and you are calling it as function doSomething() (without a value).
Or the code tries to process a property of an object which is not set.
As the code causing the error has been working before and you apparently didn't modify it, I would guess that it's the latter case: You're tossing around an object which is missing a property that should be there and should be an array.
Related
I have this following scenario:
I have a JS (parent) class that constructs/creates two other classes. The parent class is attached to window object on the client side (browser). My issue is a call in the following manner:
window.parent.create({data: window.parent.utility.getId()})
in rare occasions, like one in 200 or one in 1000 I get an error that says can't call utility of undefined!
this means that the parent class is undefined! but if it was undefined how did it even make a call to window.parent.create() ?
what could possibly allow parent to be defined on the first call then make it undefined in the inner call?
but if it was undefined how did it even make a call to window.parent.create() ?
The arguments are processed before the function is called (after all, the program needs to know the function's arguments). This is why it's failing on window.parent.utility.getId() instead of window.parent.create(), the .getId() is running first.
I'd bet that if you replaced window.parent.utility.getId() with a string literal you'd see the failure happen on the .create() call instead.
Edit as pointed out by Bergi below technically the program is accessing window.parent.create first, which will return undefined. This value doesn't matter until after the arguments are processed and it tries to call the value as a function. The getId() function fails before this happens, which is why you are seeing this specific error.
I have the following script on a page that I want to replace some system language.
<script>
function xchangemessage2()
{
xval = jQuery('[ID*="_UserMessageText"]').html();
xvalpos = xval.indexOf("We could not find your information in our system. Please search again or contact us for assistance.");
xvallen = xval.length;
if (xvalpos > 0)
{
jQuery('[ID*="_UserMessageText"]').html(xval.substring(0, xvalpos+xvallen) + ' If you provided a valid user name, an email will be sent to the email address on file.')
}
}
Sys.Application.add_load(xchangemessage2);
</script>
I keep getting
Javascript TypeError: Cannot read property 'indexOf' of undefined.
TypeError: The TypeError object represents an error when a value is not of the expected type.
You are trying to access property indexOf of variable xval which is undefined.
String.prototype.indexOf(): The indexOf() method returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex. Returns -1 if the value is not found.
Array.prototype.indexOf(): The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.
undefined: The global undefined property represents the primitive value undefined. It is one of JavaScript's primitive types.
Since undefined object is not a string or an array thus using indexOf() method gives an error. Value of xval is undefined as HTML element with id _UserMessageText is not found in DOM.
Would recommend to do go through JavaScript documentation once before using it's features to avoid errors and using JavaScript at best.
Also checkout jQuery features.
The TypeError and the script tags mean that your JS is running before your HTML code is loaded. To fix this, simply put the script tags at the very bottom of your body element, so the rest of the HTML loads before your JS.
I'm having the same issue as mentioned here: Can't access object property, even though it exists. Returns undefined
However in my case it's a property with data.hostId.id, where data comes in as full object and hostId is shown undefined when its actually present in the json object, here's how it looks:
As you can see, I'm trying to access the qgUSerHost(at the very end) from the object and it throws undefined. I tried setTimeout, not working…
I also tried the solution mentioned in that post but nothing helped.
Any ideas on this one?
I think you should access that property like this.hostAsset["qgUserHost.id"] because of the . in the property name, so it wouldn't try to access the property id from some qgUserHost object.
'this.hostAsset.qgUserHost.id' != 'this.hostAsset.qgUserHost'
I have a really weird issue, can someone explain please.
In my controller, when I am logging an object
console.log($rootScope.authUser)
it returns:
where messages is an array of objects. When I am trying to access one of the properties though:
console.log($rootScope.authUser.messages)
I am getting an empty array - different results! How is this possible 0.o
Try to use
console.log(angular.copy($rootScope.authUser))
It seems that console.log prints the complete object reference, and at the time you look at it, it has already changed. If you make a copy, the copy will not be changed further and you got the "real" output at that time.
In my Angular2 template, I have the following binding:
{{Stringify(result)}}
{{result.MyProperty}}
Stringify is a function that returns JSON.stringify of the input object. The Stringify function returned a JSON string that shows the name and value of MyProperty.
However, the second line returns a
TypeError. Cannot read property 'MyProperty' of undefined in {{result.MyProperty}}.
JSON.stringify clearly shows that this property / field exists, so why am I getting an error?
If it's there it can be accessed and JS wouldn't throw
Try instead
{{result?.MyProperty}}
maybe Angular makes an attempt to access result.MyProperty before result has a value while Stringify(result) doesn't choke on null.
When result is updated in the meantime (maybe because the value was received from the server, the view would update before you can recognized that an empty string was shown before.
Your question doesn't provide enough context to know.
See also
https://github.com/angular/angular/issues/791
https://angular.io/docs/ts/latest/guide/template-syntax.html#!#expression-operators (from a comment below - thanks to #MarkRajcok )